lazy-require
lazy-require copied to clipboard
`save` option has no effect in npm >=5
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.
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']
Lgtm, will resolve tomorrow