Closed ghost closed 7 years ago
Yeah it turns out implementing a JSON parser in zsh is actually pretty tricky 😆
Thanks for reporting, I should have time to take a look at this tomorrow.
@con-ssc can you paste your package.json
?
Sure
{
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@types/d3": "^4.5.0",
"@types/jquery": "^2.0.40",
"@types/xrm": "^8.0.37"
},
"dependencies": {
"d3": "^4.7.1",
"stylus": "^0.54.5",
"typescript": "^2.2.1"
},
"scripts": {
"stylus": "stylus -w hierarchy/src/hierarchy.styl",
"typescript": "tsc -w -p ./hierarchy",
"browser-sync": "browser-sync start --server \"hierarchy/dist\" --files \"hierarchy/src/*.*\"",
"dev": "concurrently --kill-others --prefix \"[{name}]\" --names \"STYLUS,TYPESCRIPT,HTTP\" -c \"bgBlue.bold,bgMagenta.bold,bgGreen.bold\" \"npm run stylus\" \"npm run typescript\" \"npm run browser-sync\""
}
That's working ok for me, maybe it's a tab/space issue. Are you suing tabs or spaces?
I use spaces
Strange, if I paste that package.json it works. Could you upload the file somewhere and send me the link so I can test the exact file.
or link me to the repo if it's open source.
You are right, it must have been a differen package.json since this has only two spaces indent, I go checking.
Why do you have more than two spaces of indentation?
because I have a global editor config that says 4 spaces indent
Right now, the npm autocompletion doesn't work at all :( so I cannot reproduce the error.
Hmmn, I haven't pushed any updates for a while.
If you revert to default npm formatting does it work?
Running npm install --save foo
should auto format it for you.
Ok, so I'm using the amount of spaces to determine the object depth:
cat package.json | sed -nE "/^ \"scripts\": \{$/,/^ \},?$/p"
That returns the scripts object, notice the two spaces hardcoded in. That's to stop us accidentally grabbing the wrong scripts object if the package.json looks something like this:
{
"version": "1.0.0",
"name": "some-pkg",
"scripts": {
"foo": "bar"
},
"babel": {
"scripts": {
"fizz": "buzz"
}
}
}
I can't really support your use case without adding a crazy amount of complexity to the plugin. Sorry 😕
Thanks for your effort.
would it make sense to actually use jq? because then you would just type
cat package.json | jq .scripts
./jq
If I could rely on jq
being installed on users machines that would be perfect. Unfortunately I don't think it's very common.
Good point, but can't you add dependencies to your plugin or something?
Or maybe it is just a matter with using zsh on windows
No, there's no way to add a dependency. I think some plugin managers may support external shell scripts, but this needs to work on lots of different plugin managers + standalone script.
When I use
npm run something
and the scripts object is indented, zsh-better-npm-completion adds the indentation like\ \ \ \
for 4 space indentation in front of the found script.