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

[WIP] Support for the --save and --save-dev flags #41

Merged
merged 3 commits into from Jan 31, 2016

Conversation

davej
Copy link
Contributor

@davej davej commented Jan 30, 2016

Just doing an early pr so you can take a look and let me know if I'm on the correct path or if you have other ideas about how it should be implemented.

@davej davej changed the title Preliminary support for the --save and --save-dev flags [WIP] support for the --save and --save-dev flags Jan 30, 2016
@davej davej changed the title [WIP] support for the --save and --save-dev flags [WIP] Support for the --save and --save-dev flags Jan 30, 2016
@rstacruz
Copy link
Member

looks good, what's missing from this one?

packageJson[saveType] = packageJson[saveType] || {}
installedPackages.forEach(function (dependency) {
// Assumes package name of in the format of "package-name@x.x.x"
// TODO: Support other install sources (Github, scoped pkgs etc.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use require('npm-package-arg') here... it figures that out exactly for you.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, the npm behavior is to do:

npm install --save rimraf

and it'll pick up rimraf@^2.5.1 for you based on what it resolves. Might simply need to make installMultiple() throw data of the top-level packages it installed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a neater way to do this is to make installMultiple() work like this:

installMultiple(...)
  .then(packages => {
    // sift through `packages` for ones that match `cli.input`, and save those
  })

to do this, install() should simply resolve to the necessary package data at the end:

function install (...) {
  // these stuff are already available in `install()`.
  var pkg = {
    name: 'lodash',
    fulldata: /* package.json here */,
    ...
  }

  return /* snip */
    .then(_ => pkg) // <-- resolve the Promise to that stuff so that it can be picked up later
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're correct. Have a better grasp of what I'm trying to do now. I'll pick this up tomorrow, I have to head out the door now.

@davej
Copy link
Contributor Author

davej commented Jan 30, 2016

I think all that's missing is support for other install types:

@rstacruz
Copy link
Member

oh, this has merge conflicts... but i rebased your branch for you (pr-41-rebased). You can pick it up like so:

git remote add upstream https://github.com/rstacruz/pnpm.git
git fetch upstream master
git reset --hard upstream/pr-41-rebased

@rstacruz
Copy link
Member

by the way, huge thanks! really appreciate the help.

@davej
Copy link
Contributor Author

davej commented Jan 31, 2016

Hey @rstacruz, could you take another look at this now. By the way, tests will break if the @rstacruz/tap-spec module is updated to a new version.

@rstacruz
Copy link
Member

neat! resting now but ill look at this tomorrow.

btw, how's the code base so far? did you have trouble finding your way through?

@rstacruz
Copy link
Member

everything looks ok so far, havent tested it though.

@davej
Copy link
Contributor Author

davej commented Jan 31, 2016

@rstacruz, yeah codebase is very good, didn't take me too long to ramp up. Makes sense to limit the scope to npm install too instead of trying to reimplement all of npm. I would even consider dropping --global support to be honest.

Would be good to get some CI performance benchmarks in there to make sure that we're keeping track of performance as the codebase evolves.

@rstacruz
Copy link
Member

I would even consider dropping --global support to be honest.

good point, maybe --global can just be a passthru to vanilla npm install. there may be scary voodoo involved in making a pnpm install --global work interoperably with non-pnpm global modules... would rather not think about it if it doesn't really matter.

@davej
Copy link
Contributor Author

davej commented Jan 31, 2016

Yeah, unless there's a simple way to do it that is 100% compatible with npm then I'd drop it. Day-to-day I don't do a whole lot of npm install -g so it's performance doesn't stress me out like local install does.

@rstacruz
Copy link
Member

instead of trying to reimplement all of npm

I'm also planning to reimplement whatever in npm that isn't compatible with pnpm... at the moment the only other thing (afaik) is npm uninstall.

@rstacruz
Copy link
Member

ah hell, merging this now and trusting CI, haha. thanks for your help!

rstacruz added a commit that referenced this pull request Jan 31, 2016
[WIP] Support for the --save and --save-dev flags
@rstacruz rstacruz merged commit e3cbfc4 into pnpm:master Jan 31, 2016
@davej
Copy link
Contributor Author

davej commented Jan 31, 2016

Woah, hold up, I just noticed that I overwrote some existing tests with this pr :)

@rstacruz
Copy link
Member

Oops!

@davej
Copy link
Contributor Author

davej commented Jan 31, 2016

I guess we can manually add them back in. I think what happened is that I was editing the file in my text editor when I updated to your rebased branch.

@rstacruz
Copy link
Member

btw, -O/--save-optional also exists, forgot about that

@@ -0,0 +1,14 @@
var thenify = require('thenify')
var fs = require('fs')
var writeFile = thenify(fs.writeFile)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or:

require('mz/fs').writeFile

@davej
Copy link
Contributor Author

davej commented Jan 31, 2016

Yup. One other thing that I noticed, read-pkg-up does a lot of normalization, I'm not sure that we want all of it?

For example optionalDependencies get added to dependencies: https://github.com/npm/normalize-package-data#what-normalization-currently-entails

@rstacruz
Copy link
Member

oh we definitely don't want to do that. using lib/require_json.js might be in order.

@davej
Copy link
Contributor Author

davej commented Jan 31, 2016

Do you want me to fix this pr, add the overwritten tests and squash it or will I let you fix it?

@rstacruz
Copy link
Member

a new pr would probably be better.

@davej
Copy link
Contributor Author

davej commented Jan 31, 2016

ok

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 this pull request may close these issues.

None yet

2 participants