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

save option has no effect in npm >=5 #48

Open
aduth opened this issue May 8, 2020 · 2 comments
Open

save option has no effect in npm >=5 #48

aduth opened this issue May 8, 2020 · 2 comments

Comments

@aduth
Copy link

aduth commented May 8, 2020

The implementation of the save option works by appending a --save flag if the option is provided, otherwise just calling npm install ...:

https://github.com/bevry/lazy-require/blob/34a804f02c011d3da6ed0685b2602085c9b49b4a/source/index.js#L249-L253

Unfortunately, this doesn't work after npm 5, which changed the default behavior of npm install to save by default:

npm will --save by default now

https://blog.npmjs.org/post/161081169345/v500

Thus, regardless if save option is passed as true or false or omitted altogether, it will always effect the save behavior.

@aduth
Copy link
Author

aduth commented May 8, 2020

Seems like a fix may just be to invert the condition for passing --no-save:

 const args = ['npm', 'install', name] 
 if (opts.save !== true) { 
 	args.push('--no-save') 
 	opts.save = null // {delete opts.save} is very slow 
 } 

Reference: https://docs.npmjs.com/cli/install

Not sure if there's backward-compatibility commitment to consider here, i.e. supporting Node < 5, where the default behavior would be different. In which case, I suppose it may be required to always pass a flag depending on the setting:

const args = ['npm', 'install', name, opts.save ? '--save' : '--no-save']

@balupton
Copy link
Member

Lgtm, will resolve tomorrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants