Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

api: move the unload check to sub-commands function? #8839

Closed
yorkie opened this issue Jul 6, 2015 · 3 comments
Closed

api: move the unload check to sub-commands function? #8839

yorkie opened this issue Jul 6, 2015 · 3 comments

Comments

@yorkie
Copy link
Contributor

yorkie commented Jul 6, 2015

Hey guys, I'm using npm api with Promise, but found the npm has a check on npm.load at https://github.com/npm/npm/blob/master/lib/npm.js#L175-L180. My code looks like:

const loadNpmAsync = Promise.promisify(npm.load)
const installNpmAsync = Promise.promisify(npm.commands.install)

The above would throw an unload error from lib/npm.js:176, which is caused by I accessed to the npm.commands out of the callback of npm.load, but actually at that moment, I don't want to call that function, just wanna promisify it, and will call the function in then after loadNpmAsync().

I also known we can do what I want like below:

const loadNpmAsync = Promise.promisify(npm.load)
loadNpmAsync().then(function () {
  const installNpmAsync = Promise.promisify(npm.commands.install)
})

IMHO, I just think if npm can put the unload check into sub-commands function calls, that would be neat more :)

@iarna
Copy link
Contributor

iarna commented Jul 6, 2015

We don't really support using the API today TBH, due to lots of weirdness in its shape (like this!). We strongly suggest that you call it with child_process instead.

@othiym23
Copy link
Contributor

othiym23 commented Jul 6, 2015

Yes – we have an outstanding project to remove the documentation for the API, as it's an attractive nuisance. We make no guarantees about its usefulness or fitness for any purpose other than supporting the operations of npm itself, and as such we're not going to make changes to how it's set up and used to support non-npm uses of it. I know this is a pain and probably a very unsatisfying situation for you, @yorkie, but we've got more important work right now.

@othiym23 othiym23 closed this as completed Jul 6, 2015
@yorkie
Copy link
Contributor Author

yorkie commented Jul 7, 2015

Okay, thanks a lot, it's fine :)

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

No branches or pull requests

3 participants