Can't pass right number of args via NodeJS spawnSync - javascript

Running this command using spawnSync use to work before I added in npx.
spawnSync(`npx git add-coauthor ${commandKey} "${name}" ${email}`)
Now I get an error from the git-mob cli saying Incorrect Number of Parameters. It sees four instead of three after add-coauthor it seems like it's ignoring the double quotes around name.
Error: "Incorrect Number of Parameters [ 'zsgi', 'first', 'lastname', 'someone#email.com' ]\n"
Things I've tried but I get the same error:
spawnSync(
"npx",
["git", "add-coauthor", commandKey, `"${name}"`, email]
);
spawnSync(
`npx git add-coauthor "${commandKey} \"${name}\" ${email}"`
);
If I run Git Mob cli command directly in the terminal this works:
npx git add-coauthor "jsj \"alsk la\" sls#al.com"
Grateful for any suggestions.
The code can be found here.
Edits: More info
This could be related to Windows 10 cmd as it seems to work fine on Mac OS.
Node version: 12.11.0
Npm version: 6.11.3

Related

.load Command Goes In An Infinite Loop When Trying To Load A File In Node.js REPL

I have an index.js file that I want to load in the Node REPL to try some stuff, but when I use .load index.js in the REPL, it goes in an infinite loop and keeps repeating the first line in the file const mongoose = require('mongoose');. I found an alternative solution which works in Ubuntu 20.04.5 in WSL2, which is to use the command node -i -e "$(< index.js)" in the terminal which loads the file perfectly fine and I can interact with its contents. But when I try the same command in PowerShell it gives me this error:
< : The term '<' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:15
+ node -i -e "$(< index.js)"
+ ~
+ CategoryInfo : ObjectNotFound: (<:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
C:\Program Files\nodejs\node.exe: -e requires an argument
The reason I'm asking about PowerShell "even though I use Ubuntu and things work there", is that I'm taking a web development course, and I provided the solution of using node -i -e "$(< index.js)" to people who were having the same issue, but other people can't get this to work in PowerShell, so I'm just trying to help. and I couldn't find any solution online to this .load issue, or to using the node -i -e "$(< index.js)" command in PowerShell.
index.js contents:
const mongoose = require('mongoose');
mongoose.set('strictQuery', false);
mongoose.connect('mongodb://localhost:27017/movieApp', { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
console.log("CONNECTION OPEN!!!")
})
.catch(err => {
console.log("OH NO ERROR!!!!")
console.log(err)
})
const movieSchema = new mongoose.Schema({
title: String,
year: Number,
score: Number,
rating: String
});
const Movie = mongoose.model('Movie', movieSchema);
const amadeus = new Movie({
title: 'Amadeus',
year: 1986,
score: 9.2,
rating: 'R'
});
In my experience $(...) on PowerShell acts strangely, and doesn't produce the expected result every time. Also < operator is not currently supported on Windows.
However, I managed to get the desired behaviour by using:
node -i -e echo "./index.js"
I am taking the same class. I haven't been able to get the .load index.js to work in PowerShell either -- even after updating node to the current version (v19) (rather than the LTS (v18)). But the command node -i -e "$(< index.js)" does seem to work properly if I change my VSCode terminal to gitBash (which apparently is what the course recommends, at least according to some posts from the TAs). But the command given in the lecture doesn't seem to work in any terminal shell.

Unexpected stdout of "'Saved file tree to doc-filelist.js\n' + 'Copied JS to doc-script.js\n' + 'Compiled CSS to doc-style.css\n'

I am working on a Docker Swarm data visualization tool with a team.
It works as follows:
Our backend is set up in a way that terminal commands can be executed from our code, where these terminal commands have been promisified and the result of this command should be a string of nodeIDs corresponding to the active nodes in my Docker Swarm. This data is then passed to another helper function, however, I am unable to move past the previously explained step due to an unexpected output from my promisified terminal command.
const getNodeIDs = () => {
console.log('in nodeID helper function');
return execProm("docker node ls --format '{{json .ID}}'").then(
(rawNodeIDs) => {
console.log('rawNodeIds: ', rawNodeIDs);
const parsedNodeIDs = parseRawData(rawNodeIDs);
console.log('parsedNodeIDs: ', parsedNodeIDs);
return parsedNodeIDs;
}
);
};
My code fails on line 6 due to the fact that the data being passed to my parseRawData function is not what it is expected. The console log on line 5 above returns as follows:
{
stdout: 'Saved file tree to doc-filelist.js\n' +
'Copied JS to doc-script.js\n' +
'Compiled CSS to doc-style.css\n',
stderr: ''
}
In addition to this being the wrong output, every time I invoke this command, a new file is created in my codebase labeled "docs" with the following three files inside: doc-filelist.js, doc-script.js, doc-style.css. I am working in a team of 4 other engineers, and I seem to be the only person experiencing this behavior. When I attempt to run the terminal command (featured on line 3 in the first block of code) directly in the terminal itself, I receive the expected output of
"odwch32vsynhxbc0ia2nwicag"
which is the nodeID of the single node currently in my Docker Swarm and what I should be receiving when invoking the terminal command from the code.
I've only been able to find one other stack overflow article dealing with the same issue in which that person was told to try running the terminal command
npm uninstall -g docker
which I have done, and this did not fix my issues. I've also looked into making edits to the Docker daemon itself, but am unsure that this is the real root of the issue. Since I am the only person on my team that seems to be encountering this bug, I have reason to believe that this error has something to do with my dev environment. My containers are running on Docker v4.15.0 and I am working on macOS on an M1 chip computer.
Thanks!

Command not working inside execSync in nodejs

I have one shell command which is working fine from terminal but when I try to run from nodejs it is giving me the error
Orignal Command
awk -v RS='"[^"]*"' '{n+=gsub(/\n/, "&")} END{print n}' <(sed '$s/$//' file.txt)
Node Js Code
execSync("awk -v RS='\"[^\"]*\"' '{n+=gsub(/\\n/, \"&\")} END{print n}' <(sed '$s/$//' "+ filePath+')')
The exesync is giving the same output but it is showing me the error Syntax error: "(" unexpected
<() is a bash-specific process substitution syntax. execSync defaults to using /bin/sh, usually a narrowly POSIX-compliant shell, which means it doesn't support the syntax. Explicitly use bash instead:
execSync("command goes here", {
shell: "/bin/bash"
});

Node.js on Windows Git Bash shebang failure

Windows Git Bash specific problem...
Pretty simple script which takes some user input, and does not echo it to the output. Works fine when called like node secret.js but acts strange when called as ./secret.js, needing a ctrl+c to exit, and echoing the output as you type.
#!/usr/bin/env node
var prompt = require('prompt');
prompt.start();
prompt.colors = false;
prompt.message = '';
prompt.delimiter = '';
prompt.get([{
name: 'secret',
description: 'tell me your darkest secret: ',
hidden: true
}], function(err, result){
console.log('Hey guys! He said "' + result.secret.slice(0, 5) + '..." only kidding, I won\'t tell.');
});
What is a safe way to make script run on all platforms, including git bash?
update: added env result in case it is useful...
IEUser#ie8winxp MINGW32 ~/projects/issue (develop)
$ env
HOMEPATH=\Documents and Settings\IEUser
MANPATH=/mingw32/share/man:/usr/local/man:/usr/share/man:/usr/man:/share/man:
APPDATA=C:\Documents and Settings\IEUser\Application Data
HOSTNAME=ie8winxp
SHELL=/usr/bin/bash
TERM=xterm
PROCESSOR_IDENTIFIER=x86 Family 6 Model 23 Stepping 10, GenuineIntel
WINDIR=C:\WINDOWS
TMPDIR=/tmp
OLDPWD=/c/Documents and Settings/IEUser/projects
USERDOMAIN=IE8WINXP
OS=Windows_NT
ALLUSERSPROFILE=C:\Documents and Settings\All Users
TEMP=/tmp
COMMONPROGRAMFILES=C:\Program Files\Common Files
USERNAME=IEUser
PROCESSOR_LEVEL=6
PATH=C:\Documents and Settings\IEUser\projects\issuemd\node_modules\.bin:C:\Documents and Settings\IEUser\projects\issue\node_modules\.bin:C:\Documents and Settings\IEUser\projects\node_modules\.bin:/c/Documents and Settings/IEUser/bin:/mingw32/bin:/usr/local/bin:/usr/bin:/bin:/mingw32/bin:/usr/bin:/c/Documents and Settings/IEUser/bin:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/Program Files/nodejs:/c/Documents and Settings/IEUser/Application Data/npm:/usr/bin/vendor_perl:/usr/bin/core_perl
EXEPATH=C:\Program Files\Git
FP_NO_HOST_CHECK=NO
PWD=/c/Documents and Settings/IEUser/projects/issue
SYSTEMDRIVE=C:
LANG=en_US.UTF-8
USERPROFILE=C:\Documents and Settings\IEUser
CLIENTNAME=Console
PS1=\[\033]0;$TITLEPREFIX:${PWD//[^[:ascii:]]/?}\007\]\n\[\033[32m\]\u#\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$
LOGONSERVER=\\IE8WINXP
PROCESSOR_ARCHITECTURE=x86
SSH_ASKPASS=/mingw32/libexec/git-core/git-gui--askpass
SHLVL=1
HOME=/c/Documents and Settings/IEUser
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PLINK_PROTOCOL=ssh
HOMEDRIVE=C:
MSYSTEM=MINGW32
COMSPEC=C:\WINDOWS\system32\cmd.exe
TMP=/tmp
SYSTEMROOT=C:\WINDOWS
PROCESSOR_REVISION=170a
PKG_CONFIG_PATH=/mingw32/lib/pkgconfig:/mingw32/share/pkgconfig
ACLOCAL_PATH=/mingw32/share/aclocal:/usr/share/aclocal
INFOPATH=/usr/local/info:/usr/share/info:/usr/info:/share/info:
PROGRAMFILES=C:\Program Files
DISPLAY=needs-to-be-defined
NUMBER_OF_PROCESSORS=1
SESSIONNAME=Console
COMPUTERNAME=IE8WINXP
_=/usr/bin/env
Turns out cygwin is not supported by node (and I assume git bash too).
Seems that git bash is not a real tty.
Looks like someone did something about it by bundling winpty with git bash.
Solution...
From within git bash, run winpty bash, then rest should work as expected.

Installing Node.JS on Centos 5.5

I'm trying to install Node.js on Centos 5.5, which the latest update has removed yum.
So when i'm trying to run make I get the following error. Any ideas why, or what is going on?
make -C out BUILDTYPE=Release V=1
make[1]: Entering directory `/usr/local/src/node-v0.12.0/out'
LD_LIBRARY_PATH=/usr/local/src/node-v0.12.0/out/Release/lib.host:/usr/local/src/node-v0.12.0/out/Release/lib.target:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd ../deps/v8/tools/gyp; mkdir -p /usr/local/src/node-v0.12.0/out/Release/obj/gen; python ../../tools/js2c.py "/usr/local/src/node-v0.12.0/out/Release/obj/gen/libraries.cc" CORE off ../../src/runtime.js ../../src/v8natives.js ../../src/symbol.js ../../src/array.js ../../src/string.js ../../src/uri.js ../../third_party/fdlibm/fdlibm.js ../../src/math.js ../../src/messages.js ../../src/apinatives.js ../../src/debug-debugger.js ../../src/mirror-debugger.js ../../src/liveedit-debugger.js ../../src/date.js ../../src/json.js ../../src/regexp.js ../../src/arraybuffer.js ../../src/typedarray.js ../../src/weak_collection.js ../../src/promise.js ../../src/object-observe.js ../../src/collection.js ../../src/collection-iterator.js ../../src/macros.py ../../src/array-iterator.js ../../src/string-iterator.js
File "../../tools/js2c.py", line 409
except Error as e:
^
SyntaxError: invalid syntax
make[1]: *** [/usr/local/src/node-v0.12.0/out/Release/obj/gen/libraries.cc] Error 1
make[1]: Leaving directory `/usr/local/src/node-v0.12.0/out'
make: *** [node] Error 2
I'm encountering the same issue on RHEL5. I found a work-around until this gets fixed upstream. Edit deps/v8/tools/gyp/v8.gyp and replace 'python' with 'python2.7' to force that stage of the compile to use the correct version of python.
I filed an upstream bug at https://github.com/joyent/node/issues/9217

Categories