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

Add a public API for installation and linking #125

Closed
patrickheeney opened this issue Feb 20, 2016 · 4 comments
Closed

Add a public API for installation and linking #125

patrickheeney opened this issue Feb 20, 2016 · 4 comments
Assignees

Comments

@patrickheeney
Copy link

I am using pnpm as part of a mono repo and I need to install a subset of the package.json files. Something like pnpm install -f package.local.json. Since files are not supported, I looked at integration within my own CLI tool. These are the problems I ran into:

const install = require('pnpm/lib/cmd/install');
const installError = require('pnpm/lib/err');

return install(dependencies, { quiet: false }).catch(installError);

On the surface, this looks pretty good, but it unfortunately uses the package.json from the current directory of my CLI tool as root, so it installs them in the wrong location.

const install = require('pnpm/lib/install_multiple');
const installConfig = require('pnpm/lib/config');
const installLog = require('pnpm/lib/logger');
const installError = require('pnpm/lib/err');
const installPeers = require('pnpm/lib/install/link_peers');

const ctx = {
  root: rootPath,
  store: path.resolve(rootPath, installConfig.store_path),
  log: installLog()
};

return install(ctx, dependencies, path.join(ctx.root, 'node_modules'), { quiet: false })
  .then(_ => installPeers(null, ctx.store, ctx.installs))
  .catch(installError);

This did the trick, but as you can see its pretty verbose and reaches quite a bit into the pnpm internals. It would be nice to have a public API that could do something like this:

import pnpmApi from 'pnpm/api';

return pnpmApi.install(dependencies, rootPath, { quiet: false });

The implementation would look like my last snippet above. Let me know if you would accept a pull request for this?

EDIT: Also wanted to point out that installPeers accepts pkg as a first argument, but it does not use it in the function.

@rstacruz
Copy link
Member

ah, neat! I don't think making a separate pnpm/api is the way to go here... i think it's best we make install() take the things you need—less code paths to maintain.

@davej
Copy link
Contributor

davej commented Mar 25, 2016

@patrickheeney looks good, only thing I would add is that it would be nice if it exposed an EventEmitter to track progress rather than logging to console. Perhaps even better might be a generator but that could be more difficult to implement.

@zkochan zkochan self-assigned this Aug 14, 2016
zkochan added a commit that referenced this issue Aug 14, 2016
zkochan added a commit that referenced this issue Aug 14, 2016
No breaking changes. An additional function exposed for package dependencies installation.

close #125
zkochan added a commit that referenced this issue Aug 14, 2016
No breaking changes. An additional function exposed for package dependencies installation.

close #125
@davej
Copy link
Contributor

davej commented Sep 28, 2016

@zkochan: Finally got around to using this API. Works nicely! Only thing that is missing (IMO) is to return the installed package's info. So, for example, I could find out which version was actually installed.

@zkochan
Copy link
Member

zkochan commented Sep 28, 2016

Shouldn't be hard to do it. Here that info is being written to the store.json. So we can get it from storeJson.dependencies[installedPkgName]

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.

4 participants