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

Remove "npx" from globally installed commands #61

Open
jb-adams opened this issue Oct 28, 2020 · 3 comments
Open

Remove "npx" from globally installed commands #61

jb-adams opened this issue Oct 28, 2020 · 3 comments

Comments

@jb-adams
Copy link
Member

Can we remove the npx at the beginning of the following commands, especially since the README states to install the two dependencies globally:

npx openapi bundle -f --output ${OPENAPI_JSON_PATH} ${config.apiSpecPath}
npx openapi bundle -f --output ${OPENAPI_YAML_PATH} ${config.apiSpecPath}
npx redoc-cli bundle --output ${indexPath} ${OPENAPI_YAML_PATH} ${redocOpts}

I am making a docker image of this app, and currently some of the steps are failing when the command is run with npx at the beginning.

command: npx openapi bundle -f --output openapi.yaml service-registry.yaml
error:

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /usr/src/repo/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/repo/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-10-28T14_44_20_262Z-debug.log

However when I just run: openapi bundle -f --output openapi.yaml service-registry.yaml the job completes successfully

@tschaffter
Copy link
Collaborator

tschaffter commented Nov 1, 2020

The current README says to install this tool globally with npm install -g. The reason I shy away from this is because I usually look for solution that does not require the user to modify his/her global development environment.

Using npx solves this issues but has two drawbacks:

  • Running npx <command> is slower as npx sends requests to the Internet each time it's executed
  • gh-openapi-docs cannot be used without access to Internet, which is the issue you are facing.

Proposed solution:

Rely on local install npm install + running ./node_modules/.bin/<command>

$ ./node_modules/.bin/openapi
Usage: openapi [options] [command]

Options:
  -v, --version                        Output current version of the OpenAPI CLI.
  -h, --help                           output usage information

Commands:
  bundle [options] [entryPoints...]    Create a bundle using <entryPoint> as a root document.
  validate [options] [entryPoints...]  Validate given OpenAPI 3 definition file.
  preview-docs [options] [entryPoint]  Preview API Reference docs for the specified entrypoint OAS definition

We could send the paths to the command in the config object with the default path set to ./node_modules/.bin/<command>. If the user want to use another version for some reason, he/she could overrides the paths in the config file.

@tschaffter
Copy link
Collaborator

I'm actually not sure how the above solution would work when gh-openapi-docs is installed from npmjs. The easy solution is to continue using npm install -g. Alternatively we could investigate on how to use openapi and redocly as libraries instead of running their executables.

@jb-adams
Copy link
Member Author

jb-adams commented Nov 3, 2020

Yeah, I'm good to leave this one as is. My above error was related to dependencies being incorrectly installed in the docker image, which I've since rectified.

As you mention, it'll be good once there's a library API for these packages that we can import rather than run on the command line, but last time I checked there was nothing available.

Feel free to close this issue

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