Cli: npx usage lag

Created on 21 Sep 2017  路  5Comments  路  Source: sequelize/cli

What you are doing?

As we know, together with npm 5 update we've received npx(https://github.com/zkat/npx), which allows you to run binaries for the modules installed for your project.

I'm preferring to use this approach, over the one which is stated in the docs:

node_modules/.bin/sequelize init

So I've tried, it works, but apparently it tries to install something (checks something) each time you call the binary. Here is the video:
https://monosnap.com/file/y4ia6TeNBgF9EmHdraMEWNPvRx45jH

What do you expect to happen?

I expected it will work without the installation lag.

What is actually happening?

As it is shown in the video.

__Dialect:__ not important
__Database version:__ not important
__Sequelize CLI version:__ not important
__Sequelize version:__ not important

I believe it's something connected to the package itself, as other packages are working fine with npx.

Regards,

Most helpful comment

@snewell92 sure thing, thanks for the detailed explanation.
I just thought that this is a bug, as before I was doing npx calls which did not require the npm i, probably because of the reason you've stated.

npx is still very convenient tool :)

closing the issue, and once again thanks for your explanation

All 5 comments

I am not familiar with npx , could https://github.com/zkat/npx/issues/113 this be the issue?

@sushantdhiman
I'm not sure, but might be a good guess.

However here is the video about typescript:
http://take.ms/h1kRx

as you see it doesn't do anything before the execution

@PavelPolyakov

1 - Typescript is _super_ optimized - it has 0 dependencies in its package.json, only all devDeps.

2 - npx will still npm install what it needs per process. It helps if the package is installed locally or globally so the npm install call has a chance to pull from local file system (doesn't always do that, but often it can).

3 - In your original video, the second invocation of the sequelize-cli via npx is a bit faster, so even though sequelize has to install things, npm is smart enough to cache something, at least.

4 - An alternative - instead of npx, just throw sequelize-cli in your devDeps npm i -D sequelize-cli , and run it via an npm script. npm run db:gen-mig - for whatever you need to do.

package.json

  ...
  "scripts": {
    "db:gen-mig": "sequelize migration:generate"
  }
  ...

If you need to remember what scripts you wrote, run npm run | grep sequelize and npm will show you all your scripts, which you can grep to nly show ones that use sequelize.

You can pass arguments to npm scripts too.

@snewell92 sure thing, thanks for the detailed explanation.
I just thought that this is a bug, as before I was doing npx calls which did not require the npm i, probably because of the reason you've stated.

npx is still very convenient tool :)

closing the issue, and once again thanks for your explanation

I got back to the issue recently, because I'm using sequelize-cli again. And discovered that I was doing it wrong starting from the first video.

If I do:

npx sequelize --version

everything works great, without any lag. I was probably confused with the fact that module sequelize-cli installs the binary sequelize.

Regards,

Was this page helpful?
0 / 5 - 0 ratings

Related issues

przbadu picture przbadu  路  3Comments

PavelPolyakov picture PavelPolyakov  路  6Comments

LoneWolfPR picture LoneWolfPR  路  5Comments

rmoura-92 picture rmoura-92  路  4Comments

gotrevor picture gotrevor  路  5Comments