Commit 40951a7a authored by Mike Bostock's avatar Mike Bostock
Browse files

Fix #2755.

In Node, we now use a CommonJS build with external dependencies, rather than
inlining the dependencies as is done with the UMD bundle. Thus, Node now
automatically defers to the dependent’s main entry; in the case of d3-request,
that means it inherits the XMLHttpRequest polyfill.

A slight wrinkle is that Rollup doesn’t correctly re-export the d3.event symbol
if the dependencies are not inlined. However, this is fixed by patching the
CommonJS build and replacing the event export with a getter.

This commit also removes the rollup-plugin-json dependency, and instead
generates a tiny ES6 module to export the version field from package.json.
parent 58c87223
export {
} from "./package.json";
} from "./build/version";
export {
......@@ -18,14 +18,15 @@
"name": "Mike Bostock",
"url": ""
"main": "build/d3.js",
"main": "build/d3.node.js",
"browser": "build/d3.js",
"jsnext:main": "index",
"repository": {
"type": "git",
"url": ""
"scripts": {
"pretest": "mkdir -p build && rollup -c -o build/d3.js -- index.js",
"pretest": "mkdir -p build && node -e 'process.stdout.write(\"export var version = \\\"\" + require(\"./package.json\").version + \"\\\";\\n\");' > build/version.js && rollup -c -o build/d3.js -- index.js && rollup -e `node -e 'process.stdout.write(Object.keys(require(\"./package.json\").dependencies).join(\",\"));'` -f cjs -- index.js | grep -v '^exports.event =' > build/d3.node.js && echo '\nObject.defineProperty(exports, \"event\", {get: function() { return d3Selection.event; }});' >> build/d3.node.js",
"test": "faucet `find test -name '*-test.js'`",
"prepublish": "npm run test && uglifyjs build/d3.js -c -m -o build/d3.min.js && rm -f build/ && zip -j build/ -- LICENSE build/d3.js build/d3.min.js",
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && cp -v build/d3.js ../${VERSION}.js && cp -v build/d3.min.js ../${VERSION}.min.js && cd ../ && git add d3.v${VERSION}.js d3.v${VERSION}.min.js && git commit -m \"d3 ${VERSION}\" && git push"
......@@ -33,7 +34,6 @@
"devDependencies": {
"faucet": "0.0",
"rollup": "0.25",
"rollup-plugin-json": "2",
"rollup-plugin-node-resolve": "1",
"tape": "4",
"uglify-js": "2"
import json from "rollup-plugin-json";
import node from "rollup-plugin-node-resolve";
export default {
plugins: [node({jsnext: true}), json()],
plugins: [node({jsnext: true})],
moduleName: "d3",
format: "umd"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment