-
Notifications
You must be signed in to change notification settings - Fork 3k
Passing flags and arguments into run-script #3494
Comments
There's a good deal of flexibility already. Take a look at:
|
I agree this would be nice; it's a pain to switch from |
@mfncooper I'm using all of those, yes; but the current design is extremely un-UNIXy. Neither do any of those help with the particular use-case @domenic and I are talking about. (= |
-1 |
@st-luke reasoning? Commentary? |
I think it's additional complexity that's totally unnecessary. On Tuesday, June 4, 2013, ELLIOTTCABLE wrote:
|
@ELLIOTTCABLE if it's special npm functionality/complexity to facilitate using the feature a module that is meant to be installed globally, then I think it seems incredibly silly to add this in. We should wait for the final word from @isaacs, but I truly believe there are other and better ways to do what you are trying to do than to shove this kind of code into the package manager. |
That's the thing though: installing testing runners globally is a nightmare. Much better to use the version bundled with the package you're developing/testing, which is precisely what |
Agreed, there are multiple good reasons to not do this.
Agreed, why not Maybe I'm missing something, but what's the advantage of adding this feature other than saving you a small amount of code in your test files or scripts themselves? |
@st-luke Here's the scenario. I have Now I am happily developing, and I run my tests with
But I am being a good boy and am using the locally installed mocha, via
but as discussed in this bug, this doesn't work! So what are my workarounds? Either (a) I have to either revert to using the global mocha install, with all its perils, or (b) I have to look at the contents of my
which is pretty horrid and abstraction-boundary-breaking. In both cases I lose the benefits of the The proposal in the OP is to just allow
which seems reasonable to me. |
(this isn't a bug) So this is mainly for mocha? How many other situations is this applicable to? Because these examples from the original post:
are inappropriate use of npm's scripts. |
@st-luke that's my bad, then, for not taking long enough to come up with better examples for the original report I posted. The first example, I can see how you'd consider it inappropriate. I was only using them as examples of my proposed syntax; I made the mistake of assuming that nobody sane would dispute the usefulness of the concept itself. As for examples of the use, then, let's focus on @domenic's example. It's quintessential and applicable. |
It's applicable to pretty much every test runner I've used. More generally, given the niceness of npm's scripts as a cross-platform alternative to
|
Basically, it boils down to this: there's currently no UNIX-y way to argument scripts in The only alternatives are either multiple |
Not that it's especially relevant in a pure, abstract way (as Maketarget:
$(MAKE) --something=$(FOO) --something-else=$(BAR) $ make target FOO=123 BAR=456 Raketask :target, :foo, :bar do |args|
do_something args.foo + args.bar
end $ rake target[123,456] Cakeoption '-f', '--foo [VAL]'
option '-b', '--bar [VAL]'
task 'target', 'Blah blah!', (options) ->
console.log options.foo + options.bar $ cake target --foo 123 --bar 456 Gruntgrunt.registerTask('target', "Blah blah blah.", function(foo, bar) {
console.log(foo + bar);
}); $ grunt target:123:456 Apache Ant<target name="target">
<java executable="something.exe">
<arg value="${foo}"/>
<arg value="${bar}"/>
</java>
</target> $ ant -Dfoo=123 -Dbar=456 target |
It sounds like you just want a makefile. |
@st-luke that doesn't solve the problem that the go-to invocation for all module users, is going to be
|
I would offer an alternative reason to want this feature: Say you have a framework like Sails or ActionHero, and you want provide tools for folks to generate files and run a server. If folks install the package globally ( I know I can run "local" binaries with ./node_modules/.bin/{myBinary}, but that is a rather tedious collection of commands for newcomers. Global
Local
What is being discussed here would be:
The run-script (or
Ideas copied in from the discussion here https://groups.google.com/forum/?fromgroups#!msg/npm-/XR5sRLt_9gk/hulhvU44SKQJ |
@evantahler not sure I'm understanding how what you're talking about, is an alternative to what I'm talking about. Are you proposing adopting what I'm suggesting (from your |
My example was probably more convoluted than I intended, sorry. I'm agreeing with @ELLIOTTCABLE in asking for the ability to pass argument to Basically, I would love to be able to pass arguments into As a user of the module, it seems that there are only 2 ways to execute code from a module which can take arguments:
I think both of these options would be less user-friendly being able to pass arguments to |
@domenic @isaacs I ran into exactly #3313 when trying to implement a proof-of-concept of this, ripping out the relevant bits of I'm all for waiting on #3313, then this issue's suggested changes would be an absolute breeze. (= |
+1 |
+1 I'm also using mocha and would like to pass |
+1 Supporting this would make our, and presumably a lot of other peoples', lives easier. Arguments against this seem to be unnecessary mandates. |
+1 |
Definitely +1. I don't use Makefile as I want to use something that's environment agnostic (not just for *nix systems). I don't use grunt as I already use npm which provides very close functionality with scripts. The only thing I miss from npm scripts is ability to pass the optional arguments to underlying scripts. The best way to achieve it, would probably be to append anything after |
+1 Currently I use |
Since npm run-script currently does not have a way to pass additional arguments to scripts (see <npm/npm#3494>), add a "wildcard" variable that can be used as a workaround, e.g. to run specific tests or benchmarks: ARG="--grep objrefProxy" npm -s run test ARG=utils.js npm -s run bench
What is the current status on this? |
@bucaran , it's done. Sorta. You can run You still can't put an argument in the middle of the script though. |
@rlidwka That does it! Thanks. |
Any updates on this? I still can't do |
@Morriz what version of npm are you using? Try running |
I am on version 1.4.28 because nvm installed it with node 0.10.38...tnx for pointing it out ;P
|
For those of you, like @Morriz, waiting on this feature and using |
This is a very long issue and I read through half of it, reading the original proposal a nd am already agreeing to this. I am at the point where I want ot make locally bundled tools available through scripts so I can use them in internal hooks. My app has a self-updating mechanism it can use during development. Another similar service runs on my server that is triggered during deploy. It would be convenient to use my copy of What is the current official standing on this and what are current workarounds/solutions? I am going to look into |
@IngwiePhoenix I'm the farthest thing from an official voice, but this is available in the current version of npm. You should be able to run |
@whymarrh Yes, but the problem is you can't reuse the parameters inside / the middle of your script via variables |
@whymarrh @bucaran Thanks! That actually is what I was looking for. $1 and $N are not much of an interest for me. And actually, why would it? You could write a small bit of code, pass your arguments and then proxy them from within your script. After all, it gets them in |
@IngwiePhoenix Good point. It would be useful if this was more transparent. |
@bucaran Yeah, I hear you there. I am currently setting up to use my local bower and webpack installs for some hooks in my deployment system - way easier. :) But for now the way its implemented, its totally usable and pretty nice by itself. To show a little of the method I mentioned earlier: var argv = process.argv;
var proc = require("child_process").spawn("myCommand", [
"--target="+argv[1],
// ...
]); Even if hacky, it'd be one way to work around this. I am using the Thanks to the NPM devs for working on this! |
+1 for the reusable arguments here, if it's going to happen. |
+1 for reusable arguments :) |
So, despite originally championing this, I'm 👎 on these requests for argument-reordering. This is, from my point of view, unnecessary complication; and will lead to often-changing, and even buggy(!!) Just my 2¢. Postscript: If you do want this, maybe it's time to open a new Issue? I think we can close this issue as completed. |
@ELLIOTTCABLE This issue has been closed since last August. ;) I agree with the sentiment, though – further bikeshedding feature requests in the comments on a closed issue is probably not going to get those features any closer to being implemented. |
FWIW... |
I was looking for a way to run package.json:
bash:
I think this would also work with Mocha. But any command line tool that mandates that the file argument be at the end of the line wouldn't work here. Can't think of one like that off the top of my head. Damn it would be nice if I could put a comment in my package.yaml file so that other people using the scripts would know how to use that script to run just one test. #3336 |
At the moment, there's really no way to pass arguments to scripts specified in the
"scripts"
field withnpm run-script
.I have three options, currently:
"scripts"
field. This obviously doesn't cover all situations; there's plenty of situations where I want to vary options I pass to some of the scripts, or make the scripts I write more widely applicable / configurable.WITH="--debug --optimize" npm run-scripts compile
just ain't very pretty. ;)Here's my suggestion:
-fLGs
and--flags
that come after the second extant argument torun-script
are appended to the string in the"scripts"
field before it's run--
is appended to the string in the"scripts"
field, before it's runExamples:
npm run-scripts test -- something/something_else.js
npm run-scripts a_module compile --debug --optimize
npm run-scripts clean -- -dXf
This is completely backwards-compatible with what exists now; it does mean that we'd have to explicitly name the current module if we didn't use
--
, but that's minor, when it guarantees backwards compatibility.The text was updated successfully, but these errors were encountered: