From 40951a7af30ad6dbdeaaf642172cda6fff40ef21 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Tue, 1 Mar 2016 13:31:01 -0800 Subject: [PATCH] Fix #2755. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- index.js | 2 +- package.json | 6 +++--- rollup.config.js | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index e6012f06..9aea753a 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ export { version -} from "./package.json"; +} from "./build/version"; export { bisect, diff --git a/package.json b/package.json index 71b4f8fe..8550ea68 100644 --- a/package.json +++ b/package.json @@ -18,14 +18,15 @@ "name": "Mike Bostock", "url": "http://bost.ocks.org/mike" }, - "main": "build/d3.js", + "main": "build/d3.node.js", + "browser": "build/d3.js", "jsnext:main": "index", "repository": { "type": "git", "url": "https://github.com/mbostock/d3.git" }, "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/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" @@ -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" diff --git a/rollup.config.js b/rollup.config.js index 3e0ae2a5..03a5dd7d 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,8 +1,7 @@ -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" };