-
Notifications
You must be signed in to change notification settings - Fork 240
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
RFC: reduce lifecycle script environment size #90
Conversation
bbb1365
to
4104a31
Compare
(pulled reply to this comment out so it doesn't get lost when I fix the typo)
Another approach might be, instead of only putting explicit cli configs in the environment, copy any configs that are not the default values? That would still be a larger environment, though less absurd than what we currently do. It would mean that you'll have to know Having to manage "which configs are relevant for the current command" is tricky. |
I’d be fine with providing me “not the defaults”; i think it’s totally reasonable to have to encode those, and it’s even easier if npm itself has an easy way to access them (like, if the env var is missing, i can call some shell command to print out the value, which i think i can already do with config values, just not super cheaply) |
Yep, you can do this now. Either just exec // fallbacks for absurdly old npm versions where these two environs were not provided
const node = process.env.npm_node_execpath || process.execPath
const npm = process.env.npm_execpath || 'npm'
const {spawnSync} = require('child_process')
const tag = spawnSync(node, [npm, 'config', 'get', 'tag']).stdout.toString().trim() |
The problem is that that command is incredibly slow (it’s the sole reason nvm has any performance problems, since it invokes npm config get prefix every use) - it’d be ideal to have a cheaper and easier way to do it (alternatively, if npm config get somehow got way faster) |
The slowest thing in The best approach for your use case is probably just |
Great, that's what I already have :-) and i'm totally fine with that as long as a non-default tag remains available in preversion, particularly. Thanks! |
4104a31
to
6909ebb
Compare
It looks like the |
Hmm, It would be better, if programs need to know the command being run, to have npm export a |
I use in-publish heavily; that it's not been updated in so long is solely due to npm not having broken it, not because it shouldn't be supported imo. It'd be fine if a patch of in-publish could be published that used an alternative method for npm 7+, of course! |
Yeah, I'll send a PR to @iarna to use |
@vweevers So, I think "put non-default configs in the env" would satisfy most of prebuild-install's needs, but of course it'll require a code change for the |
@isaacs SGTM. That approach (using |
A few yes... That's been around since npm 0.1.8, landed a decade ago. npm/cli@821ca21 |
On prebuild's side, it started here: prebuild/prebuild@a46eaa3. With a comment that is now answered, 5 years later:
To be sure: has npm also always translated argv flags that npm itself doesn't use, e.g. |
Not always, no. Just the last 10 years or so ;P But my guess is that install-prebuild won't work with npm 0.1.7 anyway, for a variety of other reasons.
Basically, false booleans just get set to an empty value in the environment. So you can check to see if it's either equal to |
Does "put non-default configs in the env" also work for For example, npm's default loglevel is "notice", but if that is no longer passed to |
I don't maintain But I think it's a good idea for npmlog to have the same default log level that npm has, so that should probably be updated anyway. |
I meant to suggest that someone should check |
@isaacs are we good to ratify this? |
see rfc