mbostock/d3 — pull request #624 by webmonarch (2012-04-26 05:26:21+00:00)
Title: Bootstrap d3 build without need for pre-compiled d3.v2.js and package.json

Noticing d3 used Make to build and before seeing the wiki-page @ https://github.com/mbostock/d3/wiki, I stumbled through building it using Make and figuring out npm (forgive me, I've not tried nodejs yet!).

$ make clean
$ make

That didn't work (and I figured out why)... Ultimately, I think I uncovered a couple subtle things that made bootstraping the build harder than it needed to be IMHO.

These are minor issues...but I think nice-to-have.

As a mater of taste, I don't like the idea of having build artifacts in version control...so before trying to build d3 I removed them (with `make clean`) which prompted the suggestions below:

### made `make package.json` depends on `src/core/core.js`, not pre-compiled `d3.v2.js`

Currently `npm install` depends on -> `node src/package.js` depends on -> `index.js` which depends on -> `d3.vs.js`. `index.js` requires the dependencies `vows` and `jsdom`. So, to install the d3 dependencies I need to run `src/package.js` which depends on the same dependencies... A dead end...

So, I changed `src/package.js` to require the file with version number (the only thing it needs) instead of full `d3.vs.js` which also removes the `jsdom` and `sizzle` deps in `src/package.js`.

### renamed `make install` to `make prepare`

Given it's behavior (AFAICT, it is a helper to install the nodejs dependencies needed for d3 from a compiled package.json specifying the dependencies), it made more sense to name it something else. In make conventions, `make install` is to install the compiled software onto the system, in this case, we are simply preparing the system for a build.

### `make prepare` depends on package.json

I explicitly specified this dependency in the Makefile. It seems this make target is perhaps neglected (I don't see it's predecessor `make install` anywhere in the WIKI)... but given that I know nothing about `npm`, using make for all steps of bootstrapping a build environment has appeal to me.

## Install From Source

Ultimately, after these changes, on a clean machine with only make and node, and no pre-existing build artifacts, the build becomes:

```bash
$ # Prereqs: gnu make and nodejs
make prepare
make
make test
```

compared to before:

```bash
npm install
make
make test
```

Slightly cleaner and now works in more cases.

#### Disclaimer

This was way more explanation than necessary, but I am trying to get the hang of markdown, github, and pull-requests, forgive me.

All the best!

cheers,
eric