Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: npx node-jq #614

Closed
amv opened this issue Aug 18, 2023 · 11 comments
Closed

Feature request: npx node-jq #614

amv opened this issue Aug 18, 2023 · 11 comments

Comments

@amv
Copy link

amv commented Aug 18, 2023

I would like to be able to execute jq in a project directory after "npm i" with "npx node-jq" instead of pointing to ./node_modules/node-jq/bin/jq (or maybe ./node_modules/node-jq/bin/jq.exe depending on environment?)

The reason for this is that I would like to read less documentation, and have things just work according to what I believe are common expectations in the node environments.

I am not sure how easy this would be to achieve with the binary install process you have in place, but having this in place would make it easier to reach for jq as handy tool in project scripts, and maybe maintainers familiar with the space know a way to make this happen easily. Thanks!

@davesnx
Copy link
Member

davesnx commented Aug 18, 2023

Hey, good idea.

I published a next version where you can use already npx node-jq. Install it with npm install [email protected]

It supports both names (node-jq and jq): npx node-jq "." some.json and npx jq "." some.json

We had issues in the past with the bin folder and bin property from packagejson, but lately npm has fixed those.

I will push it as a minor as soon as more platforms are tested.

Thanks for opening the issue

@amv
Copy link
Author

amv commented Aug 18, 2023

Not sure if this is the right place to report this, but this seemed to work nicely on OSX, but on vanilla Ubuntu LTS I get an "Exec format error" when trying to run the binary that was downloaded with this package:

amv@amd:~/tmptest$ npx node-jq
sh: 1: node-jq: Exec format error
amv@amd:~/tmptest$ node_modules/node-jq/bin/jq
-bash: node_modules/node-jq/bin/jq: cannot execute binary file: Exec format error
amv@amd:~/tmptest$ uname -a
Linux amd 6.2.0-26-generic #26~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jul 13 16:27:29 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.2 LTS"

The current current published version seems to work nicely also on this Linux.

@amv
Copy link
Author

amv commented Aug 18, 2023

I did some testing, and it seems that on Linux Installing [email protected] downloads a different binary package than [email protected]

The one downloaded with 3.0.0 works (and is 3 953 824 bytes), one downloaded with 4.1.0-rc.2 does not work (and is only 864 040 bytes).

@amv
Copy link
Author

amv commented Aug 18, 2023

It seems the current default version when installing from npm is v4.0.1 and it also downloads a working version of the binary on Ubuntu LTS.

@amv
Copy link
Author

amv commented Aug 18, 2023

It seems I can reproduce this problem also using the following docker command and an older Ubuntu LTS image.

sudo docker run --rm -v -it ubuntu:20.04 bash -c 'apt-get update; DEBIAN_FRONTEND=noninteractive apt-get -y install nodejs npm; cd tmp; npm i [email protected]; node_modules/node-jq/bin/jq'

This results in "Exec format error"

I managed to reproduce this on multiple machines with different network conditions (all in Finland though), so although the tests seem to be passing in Github, I am afraid that this is not just something on my machine.

For some reason, and judging by the exact same file size, it looks like the versions that are now published as rc.1 and rc.2 are downloading the "jq-osx-amd64" version of the binary also on Linux.

Same problem does not seen to occur with rc.0.

@davesnx
Copy link
Member

davesnx commented Aug 18, 2023

A little unexpected. Can you check installing node-jq@4 vs node-jq@next? It should download the same binary with the exception that next version would allow npx node-jq to work fine.

Try this steps:

npm install node-jq@next
npx node-jq "." package.json

rm -rf node_modules
npx install node-jq@4
./node_modules/node-jq/bin/jq "." package.json

@amv
Copy link
Author

amv commented Aug 18, 2023

Currently also @next seems to be resulting in the bin directory having the darwin platform version for me.

@davesnx
Copy link
Member

davesnx commented Aug 18, 2023

Released a rc3 that is tested on MacOS and Ubuntu and works fine.

@amv
Copy link
Author

amv commented Aug 18, 2023

I can confirm that npm i [email protected] seems to work also for me.

@amv
Copy link
Author

amv commented Aug 18, 2023

I think I have identified the problem with rc.2 and rc.1:

When I run NODE_JQ_SKIP_INSTALL_BINARY=true npm install [email protected] I get an empty node_modules/node-jq/bin -directory.

But when I run NODE_JQ_SKIP_INSTALL_BINARY=true npm install [email protected] I still get the darwin binary in my node_modules/node-jq/bin directory.

From this I am guessing that for some reason the rc.1 and rc.2 releases shipped with the darwin binary already in the npm package, and this prevented the Linux version from installing the correct binary as a postinstall hook.

It is a good thing that this is now fixed with rc.3, and maybe this experience also helps avoid this situation also with further npm releases :) We live and learn!

Thank you very much for putting the hours in on this very useful project!

@davesnx
Copy link
Member

davesnx commented Oct 24, 2023

Fixed in #615

@davesnx davesnx closed this as completed Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants