Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

npx as the shebang #160

Closed
andreineculau opened this issue Mar 5, 2018 · 4 comments
Closed

npx as the shebang #160

andreineculau opened this issue Mar 5, 2018 · 4 comments

Comments

@andreineculau
Copy link

I'm wondering if there was any thought of having npx as the shebang executor, so that a simple script's dependencies can be inlined in the shebang e.g.

#!/usr/bin/env npx -p ajv node -r ajv

let ajv = require('ajv');
// do more here

The above complains that it cannot find module 'ajv'.
I didn't dig deeper.

For really short scripts, where the user wouldn't care about the extra seconds in network/disk i/o, this would go a long way.

@naartjie
Copy link

I think that's a good idea, I was also thinking of something similar. Say you want to try out a library in the repl, but you're not sure you want to install it yet:

npx --package library-to-try node
const lib = require('library-to-try');

// do stuff with lib

As far as I understand it though, this is not how npx was designed, and right now this is not possible either.

@zkat
Copy link
Owner

zkat commented May 3, 2018

@andreineculau that's because npx doesn't make javascript library APIs available. Only binaries. This works, though, for your specific use case:

#!/usr/bin/env npx node@6

console.log(process.versions)

zkat added a commit that referenced this issue May 3, 2018
Ref: #160

This makes it so you can do `npx -p lodash node -r lodash` when lodash is not
already installed. One big downside of this patch is that because of the semantics
of that node feature, NODE_PATH will always be treated as a _fallback_. That is, if
you already have one version of lodash installed in a local npm project you're
currently in the directory of, you won't be able to override it with the
temporary install.
@zkat
Copy link
Owner

zkat commented May 3, 2018

See #180 :)

zkat added a commit that referenced this issue May 3, 2018
Fixes: #157
Ref: #160

This makes it so you can do `npx -p lodash node -r lodash` when lodash is not
already installed. One big downside of this patch is that because of the semantics
of that node feature, NODE_PATH will always be treated as a _fallback_. That is, if
you already have one version of lodash installed in a local npm project you're
currently in the directory of, you won't be able to override it with the
temporary install.
zkat added a commit that referenced this issue May 3, 2018
Fixes: #153
Ref: #160

This makes it so you can do `npx -p lodash node -r lodash` when lodash is not
already installed. One big downside of this patch is that because of the semantics
of that node feature, NODE_PATH will always be treated as a _fallback_. That is, if
you already have one version of lodash installed in a local npm project you're
currently in the directory of, you won't be able to override it with the
temporary install.
@zkat
Copy link
Owner

zkat commented May 3, 2018

Closing as a dupe of #153.

@zkat zkat closed this as completed May 3, 2018
zkat added a commit that referenced this issue May 4, 2018
Fixes: #153
Ref: #160

This makes it so you can do `npx -p lodash node -r lodash` when lodash is not
already installed. One big downside of this patch is that because of the semantics
of that node feature, NODE_PATH will always be treated as a _fallback_. That is, if
you already have one version of lodash installed in a local npm project you're
currently in the directory of, you won't be able to override it with the
temporary install.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants