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.
Showing
... | @@ -18,14 +18,15 @@ | ... | @@ -18,14 +18,15 @@ |
"name": "Mike Bostock", | "name": "Mike Bostock", | ||
"url": "http://bost.ocks.org/mike" | "url": "http://bost.ocks.org/mike" | ||
}, | }, | ||
"main": "build/d3.js", | "main": "build/d3.node.js", | ||
"browser": "build/d3.js", | |||
"jsnext:main": "index", | "jsnext:main": "index", | ||
"repository": { | "repository": { | ||
"type": "git", | "type": "git", | ||
"url": "https://github.com/mbostock/d3.git" | "url": "https://github.com/mbostock/d3.git" | ||
}, | }, | ||
"scripts": { | "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'`", | "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/d3.zip && zip -j build/d3.zip -- LICENSE README.md build/d3.js build/d3.min.js", | "prepublish": "npm run test && uglifyjs build/d3.js -c -m -o build/d3.min.js && rm -f build/d3.zip && zip -j build/d3.zip -- LICENSE README.md build/d3.js build/d3.min.js", | ||
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && cp -v build/d3.js ../d3.github.com/d3.v${VERSION}.js && cp -v build/d3.min.js ../d3.github.com/d3.v${VERSION}.min.js && cd ../d3.github.com && git add d3.v${VERSION}.js d3.v${VERSION}.min.js && git commit -m \"d3 ${VERSION}\" && git push" | "postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && cp -v build/d3.js ../d3.github.com/d3.v${VERSION}.js && cp -v build/d3.min.js ../d3.github.com/d3.v${VERSION}.min.js && cd ../d3.github.com && git add d3.v${VERSION}.js d3.v${VERSION}.min.js && git commit -m \"d3 ${VERSION}\" && git push" | ||
... | @@ -33,7 +34,6 @@ | ... | @@ -33,7 +34,6 @@ |
"devDependencies": { | "devDependencies": { | ||
"faucet": "0.0", | "faucet": "0.0", | ||
"rollup": "0.25", | "rollup": "0.25", | ||
"rollup-plugin-json": "2", | |||
"rollup-plugin-node-resolve": "1", | "rollup-plugin-node-resolve": "1", | ||
"tape": "4", | "tape": "4", | ||
"uglify-js": "2" | "uglify-js": "2" | ||
... | ... |
Please register or sign in to comment