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

Compare with REPL, "node -p" & "node -e" has different default imports packages #4069

Closed
rufushuang opened this issue Nov 30, 2015 · 11 comments
Labels
feature request Issues that request new features to be added to Node.js. repl Issues and PRs related to the REPL subsystem.

Comments

@rufushuang
Copy link

When in REPL, we can use packages such as fs, vm directly by default.

But in "node -p"/"node -e", must require these packages manually

node -p "fs"

returns "fs is not defined"

This makes command line script running such a pain...

Try "node -p", then "not defined" one found, and then require the missing package manually. Repeat this again and again.

@ChALkeR ChALkeR added the repl Issues and PRs related to the REPL subsystem. label Nov 30, 2015
@ChALkeR
Copy link
Member

ChALkeR commented Nov 30, 2015

When in REPL, we can use packages such as fs, vm directly by default.

This is documented as a repl-only feature: https://nodejs.org/api/repl.html#repl_repl_features

@Fishrock123
Copy link
Contributor

We could maybe add a cli flag for this?

@rufushuang would that be acceptable? something like --auto-import --exec "<script>" /
-ae "<script>"?

@Fishrock123 Fishrock123 added the feature request Issues that request new features to be added to Node.js. label Nov 30, 2015
@Fishrock123
Copy link
Contributor

@evanlucas did you ever get around to working more on the options parser? What part of the work in blocking progress?

@evanlucas
Copy link
Contributor

I have played with it on and off. I'm having a lot of difficulty making sure that it is backwards compatible though (particularly the p and e arguments)

@Fishrock123
Copy link
Contributor

@evanlucas hmmm, ok. Just as a note, special casing a thing or two might not be bad overall for now.

@Fishrock123
Copy link
Contributor

Fwiw this request is actually pretty tricky.

@evanlucas
Copy link
Contributor

You could always do this:

$ cat req.js

global.fs = require('fs')

$ node --require ./req.js -pe fs

@rufushuang
Copy link
Author

Sorry for the late reply, i kinda understand this is backwards compatible consideration.

If it's same package imports, both the direct file execution and "-p"/"-e" option. Then remain this request as the only REPL feature is OK.

Maybe some more documents on "-p"/"-e" options?

@Fishrock123
Copy link
Contributor

I think there should be an extra CLI option for this. :)

@addaleax
Copy link
Member

I think this has been resolved by #6207? Sorry, I didn’t see this issue before, originally the PR wasn’t supposed to change anything for the repl. @Fishrock123 @evanlucas You commented both here and there, do any of the concerns voiced here apply?

@Fishrock123
Copy link
Contributor

Sounds like this can be closed.

@jasnell jasnell closed this as completed May 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

No branches or pull requests

6 participants