Initial support for `resolve.npm`.

Review Request #2723 - Created Aug. 28, 2015 and submitted

John Sirois
2073, 2087
2738, 2737, 2736
stuhood, tejal, zundel

This is pants implementing npm install for node projects modeled in
pants. The driving concern is primary control by pants of Node.js
packages via BUILD files, and this necessitates generating package.json
files under .pants.d/ to describe dependencies (and later more) to
npm so it can resolve both local and remote dependencies. A second
fallout is copying pants controlled node module sourcecode up into
.pants.d/ since node has a documented behavior of resolving against
realpath[1], foiling any attempt to use symlinks.

The basic targets needed to support resolve.npm - aka npm install
are added along with basic tests for the functionality.


contrib/node/BUILD | 3 ++
contrib/node/examples/3rdparty/node/BUILD | 0
contrib/node/src/python/pants/contrib/node/BUILD | 18 +++++++
contrib/node/src/python/pants/contrib/node/ | 26 ++++++++++
contrib/node/src/python/pants/contrib/node/targets/BUILD | 39 ++++++++++++++
contrib/node/src/python/pants/contrib/node/targets/ | 0
contrib/node/src/python/pants/contrib/node/targets/ | 41 +++++++++++++++
contrib/node/src/python/pants/contrib/node/targets/ | 40 +++++++++++++++
contrib/node/src/python/pants/contrib/node/targets/ | 33 ++++++++++++
contrib/node/src/python/pants/contrib/node/tasks/BUILD | 35 +++++++++++++
contrib/node/src/python/pants/contrib/node/tasks/ | 0
contrib/node/src/python/pants/contrib/node/tasks/ | 83 ++++++++++++++++++++++++++++++
contrib/node/src/python/pants/contrib/node/tasks/ | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++
contrib/node/tests/python/pants_test/contrib/node/targets/BUILD | 28 ++++++++++
contrib/node/tests/python/pants_test/contrib/node/targets/ | 0
contrib/node/tests/python/pants_test/contrib/node/targets/ | 31 +++++++++++
contrib/node/tests/python/pants_test/contrib/node/targets/ | 26 ++++++++++
contrib/node/tests/python/pants_test/contrib/node/tasks/BUILD | 36 +++++++++++++
contrib/node/tests/python/pants_test/contrib/node/tasks/ | 0
contrib/node/tests/python/pants_test/contrib/node/tasks/ | 79 ++++++++++++++++++++++++++++
contrib/node/tests/python/pants_test/contrib/node/tasks/ | 122 +++++++++++++++++++++++++++++++++++++++++++
pants.ini | 1 +
22 files changed, 781 insertions(+)

I manually confirmed that with the NpmResolve execution of npm dedupe
commented out, the dedupe portion of the
NpmResolveTest.test_resolve_simple_graph test failed like so:

E     AssertionError: Expected to find exactly 1 de-duped `typ` package, but found these:
E       node_modules/typ/package.json
E       node_modules/util/node_modules/typ/package.json

CI went green here:

John Sirois
John Sirois
Eric Ayers
John Sirois
John Sirois
John Sirois
John Sirois
John Sirois
Review request changed

Status: Closed (submitted)

Stu Hood

Thanks a lot John!

  1. Both items below addressed here:

From a 1:1:1 perspective, this seems like a dangerous thing to expose... can we pre-deprecate it?

  1. Definitely.  This appears to be copypasta plain and simple and we seem to have an awful lot of it in target constructors - unused in the pants repo at any rate.  I'm not sure if Twitter, Square or Foursquare use this in internal plugins ... I'll ping folks and straight up kill if not in the other spots its aped, but follow up and kill it here immediately.
  2. We do have it in our ruby_specs() plugin but I'll be happy to update the code.

  3. Eric agreed here and Stu & Patrick agreed in so the full fix:

Would be good if this was explicitly abstract... was confused for a minute.

  1. I could mix in AbstractClass - although Target already is one - but it would only be for doc since there are no @abstractmethod/@abstractproperty. As such I'd prefer just documenting in the traditional way and/or adding a type-check in __init__ that raises if == NpmPackage.

    Your call.

  2. Documenting would be fine, thanks.