From 890fc031ac9def3667c70f3cd64edb664fc954db Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Wed, 2 May 2018 23:48:53 +1000 Subject: [PATCH 1/5] Support native ESM via .mjs. Relates to https://github.com/graphql/express-graphql/issues/425. - Swapped deprecated babel-preset-es2015 for babel-preset-env. - Added package.json engines field. - Configured babel-preset-env to target the Node.js version defined in package.json engines field. - Kept Babel at v6, but moved config into a v7 ready .babelrc.js file for dynamic config via env. - Tidied the package.json scripts, added an ESM build step that generates .mjs dist files. Follow the lead of https://github.com/graphql/graphql-js/pull/1244, although I do things quite different for my own projects with Babel v7. - Updated package.json main field for ESM/CJS cross compatibility. - Added a package.json module field for tree-shaking bundlers. --- .babelrc.js | 15 ++++++ package.json | 21 ++++---- yarn.lock | 147 +++++++++++++++++++++++++++++++++++---------------- 3 files changed, 129 insertions(+), 54 deletions(-) create mode 100644 .babelrc.js diff --git a/.babelrc.js b/.babelrc.js new file mode 100644 index 00000000..574e4773 --- /dev/null +++ b/.babelrc.js @@ -0,0 +1,15 @@ +module.exports = { + presets: [ + [ + 'env', + { + modules: process.env.ESM ? false : 'commonjs', + targets: { + node: require('./package.json').engines.node.substring(2), // Strip `>=` + }, + }, + ], + ], + plugins: ['transform-class-properties', 'transform-flow-strip-types'], + ignore: ['__tests__'], +}; diff --git a/package.json b/package.json index 32d79c9b..3264feac 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,11 @@ "middleware", "api" ], - "main": "dist/index.js", + "engines": { + "node": ">=4" + }, + "main": "dist/index", + "module": "dist/index.mjs", "directories": { "lib": "./dist" }, @@ -34,26 +38,25 @@ }, "babel": { "presets": [ - "es2015" - ], - "plugins": [ - "transform-class-properties", - "transform-flow-strip-types" + "./.babelrc.js" ] }, "scripts": { - "prepublish": ". ./resources/prepublish.sh", "test": "npm run lint && npm run check && npm run testonly", "testonly": "mocha $npm_package_options_mocha", "lint": "eslint src", "prettier": "prettier --write 'src/**/*.js'", "check": "flow check", - "build": "rm -rf dist/* && babel src --ignore __tests__ --out-dir dist && npm run build:flow", + "build": "npm run build:clean && npm run build:esm && npm run build:cjs && npm run build:flow", + "build:clean": "rm -rf dist/*", + "build:esm": "ESM=1 babel src -d dist/esm && for file in $(find dist/esm -name '*.js'); do mv \"$file\" `echo \"$file\" | sed 's/dist\\/esm/dist/g; s/.js$/.mjs/g'`; done && rm -rf dist/esm", + "build:cjs": "babel src -d dist", "build:flow": "find ./src -name '*.js' -not -path '*/__tests__*' | while read filepath; do cp $filepath `echo $filepath | sed 's/\\/src\\//\\/dist\\//g'`.flow; done", "watch": "node resources/watch.js", "cover": "babel-node node_modules/.bin/isparta cover --root src --report html node_modules/.bin/_mocha -- $npm_package_options_mocha", "cover:lcov": "babel-node node_modules/.bin/isparta cover --root src --report lcovonly node_modules/.bin/_mocha -- $npm_package_options_mocha", "preversion": "npm test", + "prepublish": ". ./resources/prepublish.sh", "start": "babel-node examples/index.js" }, "dependencies": { @@ -69,7 +72,7 @@ "babel-plugin-transform-class-properties": "6.24.1", "babel-plugin-transform-flow-strip-types": "6.22.0", "babel-plugin-transform-runtime": "^6.23.0", - "babel-preset-es2015": "6.24.1", + "babel-preset-env": "^1.6.1", "babel-register": "^6.26.0", "babel-runtime": "^6.26.0", "body-parser": "1.18.2", diff --git a/yarn.lock b/yarn.lock index 60944b98..43eeed0a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -347,6 +347,14 @@ babel-generator@^6.26.0: source-map "^0.5.6" trim-right "^1.0.1" +babel-helper-builder-binary-assignment-operator-visitor@^6.24.1: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-helper-builder-binary-assignment-operator-visitor/-/babel-helper-builder-binary-assignment-operator-visitor-6.24.1.tgz#cce4517ada356f4220bcae8a02c2b346f9a56664" + dependencies: + babel-helper-explode-assignable-expression "^6.24.1" + babel-runtime "^6.22.0" + babel-types "^6.24.1" + babel-helper-call-delegate@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-helper-call-delegate/-/babel-helper-call-delegate-6.24.1.tgz#ece6aacddc76e41c3461f88bfc575bd0daa2df8d" @@ -365,6 +373,14 @@ babel-helper-define-map@^6.24.1: babel-types "^6.26.0" lodash "^4.17.4" +babel-helper-explode-assignable-expression@^6.24.1: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-helper-explode-assignable-expression/-/babel-helper-explode-assignable-expression-6.24.1.tgz#f25b82cf7dc10433c55f70592d5746400ac22caa" + dependencies: + babel-runtime "^6.22.0" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + babel-helper-function-name@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-helper-function-name/-/babel-helper-function-name-6.24.1.tgz#d3475b8c03ed98242a25b48351ab18399d3580a9" @@ -452,11 +468,19 @@ babel-plugin-syntax-class-properties@^6.8.0: version "6.13.0" resolved "https://registry.yarnpkg.com/babel-plugin-syntax-class-properties/-/babel-plugin-syntax-class-properties-6.13.0.tgz#d7eb23b79a317f8543962c505b827c7d6cac27de" +babel-plugin-syntax-exponentiation-operator@^6.8.0: + version "6.13.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-exponentiation-operator/-/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz#9ee7e8337290da95288201a6a57f4170317830de" + babel-plugin-syntax-flow@^6.18.0: version "6.18.0" resolved "https://registry.yarnpkg.com/babel-plugin-syntax-flow/-/babel-plugin-syntax-flow-6.18.0.tgz#4c3ab20a2af26aa20cd25995c398c4eb70310c8d" -babel-plugin-transform-async-to-generator@6.24.1: +babel-plugin-syntax-trailing-function-commas@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-6.22.0.tgz#ba0360937f8d06e40180a43fe0d5616fff532cf3" + +babel-plugin-transform-async-to-generator@6.24.1, babel-plugin-transform-async-to-generator@^6.22.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-to-generator/-/babel-plugin-transform-async-to-generator-6.24.1.tgz#6536e378aff6cb1d5517ac0e40eb3e9fc8d08761" dependencies: @@ -485,7 +509,7 @@ babel-plugin-transform-es2015-block-scoped-functions@^6.22.0: dependencies: babel-runtime "^6.22.0" -babel-plugin-transform-es2015-block-scoping@^6.24.1: +babel-plugin-transform-es2015-block-scoping@^6.23.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-block-scoping/-/babel-plugin-transform-es2015-block-scoping-6.26.0.tgz#d70f5299c1308d05c12f463813b0a09e73b1895f" dependencies: @@ -495,7 +519,7 @@ babel-plugin-transform-es2015-block-scoping@^6.24.1: babel-types "^6.26.0" lodash "^4.17.4" -babel-plugin-transform-es2015-classes@^6.24.1: +babel-plugin-transform-es2015-classes@^6.23.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-classes/-/babel-plugin-transform-es2015-classes-6.24.1.tgz#5a4c58a50c9c9461e564b4b2a3bfabc97a2584db" dependencies: @@ -509,33 +533,33 @@ babel-plugin-transform-es2015-classes@^6.24.1: babel-traverse "^6.24.1" babel-types "^6.24.1" -babel-plugin-transform-es2015-computed-properties@^6.24.1: +babel-plugin-transform-es2015-computed-properties@^6.22.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-computed-properties/-/babel-plugin-transform-es2015-computed-properties-6.24.1.tgz#6fe2a8d16895d5634f4cd999b6d3480a308159b3" dependencies: babel-runtime "^6.22.0" babel-template "^6.24.1" -babel-plugin-transform-es2015-destructuring@^6.22.0: +babel-plugin-transform-es2015-destructuring@^6.23.0: version "6.23.0" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-destructuring/-/babel-plugin-transform-es2015-destructuring-6.23.0.tgz#997bb1f1ab967f682d2b0876fe358d60e765c56d" dependencies: babel-runtime "^6.22.0" -babel-plugin-transform-es2015-duplicate-keys@^6.24.1: +babel-plugin-transform-es2015-duplicate-keys@^6.22.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-duplicate-keys/-/babel-plugin-transform-es2015-duplicate-keys-6.24.1.tgz#73eb3d310ca969e3ef9ec91c53741a6f1576423e" dependencies: babel-runtime "^6.22.0" babel-types "^6.24.1" -babel-plugin-transform-es2015-for-of@^6.22.0: +babel-plugin-transform-es2015-for-of@^6.23.0: version "6.23.0" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-for-of/-/babel-plugin-transform-es2015-for-of-6.23.0.tgz#f47c95b2b613df1d3ecc2fdb7573623c75248691" dependencies: babel-runtime "^6.22.0" -babel-plugin-transform-es2015-function-name@^6.24.1: +babel-plugin-transform-es2015-function-name@^6.22.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-function-name/-/babel-plugin-transform-es2015-function-name-6.24.1.tgz#834c89853bc36b1af0f3a4c5dbaa94fd8eacaa8b" dependencies: @@ -549,7 +573,7 @@ babel-plugin-transform-es2015-literals@^6.22.0: dependencies: babel-runtime "^6.22.0" -babel-plugin-transform-es2015-modules-amd@^6.24.1: +babel-plugin-transform-es2015-modules-amd@^6.22.0, babel-plugin-transform-es2015-modules-amd@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-amd/-/babel-plugin-transform-es2015-modules-amd-6.24.1.tgz#3b3e54017239842d6d19c3011c4bd2f00a00d154" dependencies: @@ -557,16 +581,16 @@ babel-plugin-transform-es2015-modules-amd@^6.24.1: babel-runtime "^6.22.0" babel-template "^6.24.1" -babel-plugin-transform-es2015-modules-commonjs@^6.24.1: - version "6.26.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.26.0.tgz#0d8394029b7dc6abe1a97ef181e00758dd2e5d8a" +babel-plugin-transform-es2015-modules-commonjs@^6.23.0, babel-plugin-transform-es2015-modules-commonjs@^6.24.1: + version "6.26.2" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.26.2.tgz#58a793863a9e7ca870bdc5a881117ffac27db6f3" dependencies: babel-plugin-transform-strict-mode "^6.24.1" babel-runtime "^6.26.0" babel-template "^6.26.0" babel-types "^6.26.0" -babel-plugin-transform-es2015-modules-systemjs@^6.24.1: +babel-plugin-transform-es2015-modules-systemjs@^6.23.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-systemjs/-/babel-plugin-transform-es2015-modules-systemjs-6.24.1.tgz#ff89a142b9119a906195f5f106ecf305d9407d23" dependencies: @@ -574,7 +598,7 @@ babel-plugin-transform-es2015-modules-systemjs@^6.24.1: babel-runtime "^6.22.0" babel-template "^6.24.1" -babel-plugin-transform-es2015-modules-umd@^6.24.1: +babel-plugin-transform-es2015-modules-umd@^6.23.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-umd/-/babel-plugin-transform-es2015-modules-umd-6.24.1.tgz#ac997e6285cd18ed6176adb607d602344ad38468" dependencies: @@ -582,14 +606,14 @@ babel-plugin-transform-es2015-modules-umd@^6.24.1: babel-runtime "^6.22.0" babel-template "^6.24.1" -babel-plugin-transform-es2015-object-super@^6.24.1: +babel-plugin-transform-es2015-object-super@^6.22.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-object-super/-/babel-plugin-transform-es2015-object-super-6.24.1.tgz#24cef69ae21cb83a7f8603dad021f572eb278f8d" dependencies: babel-helper-replace-supers "^6.24.1" babel-runtime "^6.22.0" -babel-plugin-transform-es2015-parameters@^6.24.1: +babel-plugin-transform-es2015-parameters@^6.23.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-parameters/-/babel-plugin-transform-es2015-parameters-6.24.1.tgz#57ac351ab49caf14a97cd13b09f66fdf0a625f2b" dependencies: @@ -600,7 +624,7 @@ babel-plugin-transform-es2015-parameters@^6.24.1: babel-traverse "^6.24.1" babel-types "^6.24.1" -babel-plugin-transform-es2015-shorthand-properties@^6.24.1: +babel-plugin-transform-es2015-shorthand-properties@^6.22.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-shorthand-properties/-/babel-plugin-transform-es2015-shorthand-properties-6.24.1.tgz#24f875d6721c87661bbd99a4622e51f14de38aa0" dependencies: @@ -613,7 +637,7 @@ babel-plugin-transform-es2015-spread@^6.22.0: dependencies: babel-runtime "^6.22.0" -babel-plugin-transform-es2015-sticky-regex@^6.24.1: +babel-plugin-transform-es2015-sticky-regex@^6.22.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-sticky-regex/-/babel-plugin-transform-es2015-sticky-regex-6.24.1.tgz#00c1cdb1aca71112cdf0cf6126c2ed6b457ccdbc" dependencies: @@ -627,13 +651,13 @@ babel-plugin-transform-es2015-template-literals@^6.22.0: dependencies: babel-runtime "^6.22.0" -babel-plugin-transform-es2015-typeof-symbol@^6.22.0: +babel-plugin-transform-es2015-typeof-symbol@^6.23.0: version "6.23.0" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-typeof-symbol/-/babel-plugin-transform-es2015-typeof-symbol-6.23.0.tgz#dec09f1cddff94b52ac73d505c84df59dcceb372" dependencies: babel-runtime "^6.22.0" -babel-plugin-transform-es2015-unicode-regex@^6.24.1: +babel-plugin-transform-es2015-unicode-regex@^6.22.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-unicode-regex/-/babel-plugin-transform-es2015-unicode-regex-6.24.1.tgz#d38b12f42ea7323f729387f18a7c5ae1faeb35e9" dependencies: @@ -641,6 +665,14 @@ babel-plugin-transform-es2015-unicode-regex@^6.24.1: babel-runtime "^6.22.0" regexpu-core "^2.0.0" +babel-plugin-transform-exponentiation-operator@^6.22.0: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-exponentiation-operator/-/babel-plugin-transform-exponentiation-operator-6.24.1.tgz#2ab0c9c7f3098fa48907772bb813fe41e8de3a0e" + dependencies: + babel-helper-builder-binary-assignment-operator-visitor "^6.24.1" + babel-plugin-syntax-exponentiation-operator "^6.8.0" + babel-runtime "^6.22.0" + babel-plugin-transform-flow-strip-types@6.22.0: version "6.22.0" resolved "https://registry.yarnpkg.com/babel-plugin-transform-flow-strip-types/-/babel-plugin-transform-flow-strip-types-6.22.0.tgz#84cb672935d43714fdc32bce84568d87441cf7cf" @@ -648,7 +680,7 @@ babel-plugin-transform-flow-strip-types@6.22.0: babel-plugin-syntax-flow "^6.18.0" babel-runtime "^6.22.0" -babel-plugin-transform-regenerator@^6.24.1: +babel-plugin-transform-regenerator@^6.22.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-plugin-transform-regenerator/-/babel-plugin-transform-regenerator-6.26.0.tgz#e0703696fbde27f0a3efcacf8b4dca2f7b3a8f2f" dependencies: @@ -675,34 +707,40 @@ babel-polyfill@^6.26.0: core-js "^2.5.0" regenerator-runtime "^0.10.5" -babel-preset-es2015@6.24.1: - version "6.24.1" - resolved "https://registry.yarnpkg.com/babel-preset-es2015/-/babel-preset-es2015-6.24.1.tgz#d44050d6bc2c9feea702aaf38d727a0210538939" +babel-preset-env@^1.6.1: + version "1.6.1" + resolved "https://registry.yarnpkg.com/babel-preset-env/-/babel-preset-env-1.6.1.tgz#a18b564cc9b9afdf4aae57ae3c1b0d99188e6f48" dependencies: babel-plugin-check-es2015-constants "^6.22.0" + babel-plugin-syntax-trailing-function-commas "^6.22.0" + babel-plugin-transform-async-to-generator "^6.22.0" babel-plugin-transform-es2015-arrow-functions "^6.22.0" babel-plugin-transform-es2015-block-scoped-functions "^6.22.0" - babel-plugin-transform-es2015-block-scoping "^6.24.1" - babel-plugin-transform-es2015-classes "^6.24.1" - babel-plugin-transform-es2015-computed-properties "^6.24.1" - babel-plugin-transform-es2015-destructuring "^6.22.0" - babel-plugin-transform-es2015-duplicate-keys "^6.24.1" - babel-plugin-transform-es2015-for-of "^6.22.0" - babel-plugin-transform-es2015-function-name "^6.24.1" + babel-plugin-transform-es2015-block-scoping "^6.23.0" + babel-plugin-transform-es2015-classes "^6.23.0" + babel-plugin-transform-es2015-computed-properties "^6.22.0" + babel-plugin-transform-es2015-destructuring "^6.23.0" + babel-plugin-transform-es2015-duplicate-keys "^6.22.0" + babel-plugin-transform-es2015-for-of "^6.23.0" + babel-plugin-transform-es2015-function-name "^6.22.0" babel-plugin-transform-es2015-literals "^6.22.0" - babel-plugin-transform-es2015-modules-amd "^6.24.1" - babel-plugin-transform-es2015-modules-commonjs "^6.24.1" - babel-plugin-transform-es2015-modules-systemjs "^6.24.1" - babel-plugin-transform-es2015-modules-umd "^6.24.1" - babel-plugin-transform-es2015-object-super "^6.24.1" - babel-plugin-transform-es2015-parameters "^6.24.1" - babel-plugin-transform-es2015-shorthand-properties "^6.24.1" + babel-plugin-transform-es2015-modules-amd "^6.22.0" + babel-plugin-transform-es2015-modules-commonjs "^6.23.0" + babel-plugin-transform-es2015-modules-systemjs "^6.23.0" + babel-plugin-transform-es2015-modules-umd "^6.23.0" + babel-plugin-transform-es2015-object-super "^6.22.0" + babel-plugin-transform-es2015-parameters "^6.23.0" + babel-plugin-transform-es2015-shorthand-properties "^6.22.0" babel-plugin-transform-es2015-spread "^6.22.0" - babel-plugin-transform-es2015-sticky-regex "^6.24.1" + babel-plugin-transform-es2015-sticky-regex "^6.22.0" babel-plugin-transform-es2015-template-literals "^6.22.0" - babel-plugin-transform-es2015-typeof-symbol "^6.22.0" - babel-plugin-transform-es2015-unicode-regex "^6.24.1" - babel-plugin-transform-regenerator "^6.24.1" + babel-plugin-transform-es2015-typeof-symbol "^6.23.0" + babel-plugin-transform-es2015-unicode-regex "^6.22.0" + babel-plugin-transform-exponentiation-operator "^6.22.0" + babel-plugin-transform-regenerator "^6.22.0" + browserslist "^2.1.2" + invariant "^2.2.2" + semver "^5.3.0" babel-register@^6.26.0: version "6.26.0" @@ -885,6 +923,13 @@ browser-stdout@1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.0.tgz#f351d32969d32fa5d7a5567154263d928ae3bd1f" +browserslist@^2.1.2: + version "2.11.3" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-2.11.3.tgz#fe36167aed1bbcde4827ebfe71347a2cc70b99b2" + dependencies: + caniuse-lite "^1.0.30000792" + electron-to-chromium "^1.3.30" + bser@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/bser/-/bser-2.0.0.tgz#9ac78d3ed5d915804fd87acb158bc797147a1719" @@ -933,6 +978,10 @@ camelcase@^1.0.2: version "1.2.1" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-1.2.1.tgz#9bb5304d2e0b56698b2c758b08a3eaa9daa58a39" +caniuse-lite@^1.0.30000792: + version "1.0.30000833" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000833.tgz#98e84fcdb4399c6fa0b0fd41490d3217ac7802b4" + caseless@~0.12.0: version "0.12.0" resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" @@ -1458,6 +1507,10 @@ ee-first@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" +electron-to-chromium@^1.3.30: + version "1.3.45" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.45.tgz#458ac1b1c5c760ce8811a16d2bfbd97ec30bafb8" + encodeurl@~1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.1.tgz#79e3d58655346909fe6f0f45a5de68103b294d20" @@ -3033,7 +3086,11 @@ prettier@^1.10.2: version "1.10.2" resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.10.2.tgz#1af8356d1842276a99a5b5529c82dd9e9ad3cc93" -private@^0.1.6, private@^0.1.7: +private@^0.1.6: + version "0.1.8" + resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff" + +private@^0.1.7: version "0.1.7" resolved "https://registry.yarnpkg.com/private/-/private-0.1.7.tgz#68ce5e8a1ef0a23bb570cc28537b5332aba63ef1" @@ -3172,8 +3229,8 @@ readdirp@^2.0.0: set-immediate-shim "^1.0.1" regenerate@^1.2.1: - version "1.3.2" - resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.2.tgz#d1941c67bad437e1be76433add5b385f95b19260" + version "1.3.3" + resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.3.tgz#0c336d3980553d755c39b586ae3b20aa49c82b7f" regenerator-runtime@^0.10.5: version "0.10.5" From f2adf5bd6248a31da8864ed4e0c3d424fa2cd61a Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Thu, 3 May 2018 00:25:52 +1000 Subject: [PATCH 2/5] Fix test transpilation. --- .babelrc.js | 3 +-- package.json | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.babelrc.js b/.babelrc.js index 574e4773..90641c4c 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -10,6 +10,5 @@ module.exports = { }, ], ], - plugins: ['transform-class-properties', 'transform-flow-strip-types'], - ignore: ['__tests__'], + plugins: ['transform-class-properties', 'transform-flow-strip-types'] }; diff --git a/package.json b/package.json index 3264feac..82f89052 100644 --- a/package.json +++ b/package.json @@ -49,8 +49,8 @@ "check": "flow check", "build": "npm run build:clean && npm run build:esm && npm run build:cjs && npm run build:flow", "build:clean": "rm -rf dist/*", - "build:esm": "ESM=1 babel src -d dist/esm && for file in $(find dist/esm -name '*.js'); do mv \"$file\" `echo \"$file\" | sed 's/dist\\/esm/dist/g; s/.js$/.mjs/g'`; done && rm -rf dist/esm", - "build:cjs": "babel src -d dist", + "build:esm": "ESM=1 babel src -d dist/esm --ignore __tests__ && for file in $(find dist/esm -name '*.js'); do mv \"$file\" `echo \"$file\" | sed 's/dist\\/esm/dist/g; s/.js$/.mjs/g'`; done && rm -rf dist/esm", + "build:cjs": "babel src -d dist --ignore __tests__", "build:flow": "find ./src -name '*.js' -not -path '*/__tests__*' | while read filepath; do cp $filepath `echo $filepath | sed 's/\\/src\\//\\/dist\\//g'`.flow; done", "watch": "node resources/watch.js", "cover": "babel-node node_modules/.bin/isparta cover --root src --report html node_modules/.bin/_mocha -- $npm_package_options_mocha", From 28cace0af498659e6f3727712cb448cb3ac0ffaa Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Thu, 3 May 2018 00:27:00 +1000 Subject: [PATCH 3/5] Fix index ESM exports. This one needs careful consideration. --- src/index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index a8a81a11..13a35a0c 100644 --- a/src/index.js +++ b/src/index.js @@ -138,8 +138,7 @@ type Middleware = (request: $Request, response: $Response) => Promise; * Middleware for express; takes an options object or function as input to * configure behavior, and returns an express middleware. */ -module.exports = graphqlHTTP; -function graphqlHTTP(options: Options): Middleware { +export default function graphqlHTTP(options: Options): Middleware { if (!options) { throw new Error('GraphQL middleware requires options.'); } @@ -381,8 +380,7 @@ export type GraphQLParams = { * Provided a "Request" provided by express or connect (typically a node style * HTTPClientRequest), Promise the GraphQL request parameters. */ -module.exports.getGraphQLParams = getGraphQLParams; -function getGraphQLParams(request: $Request): Promise { +export function getGraphQLParams(request: $Request): Promise { return parseBody(request).then(bodyData => { const urlData = (request.url && url.parse(request.url, true).query) || {}; return parseGraphQLParams(urlData, bodyData); From cb84e76952f7fb22660a001881c28ee078e63353 Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Mon, 7 May 2018 12:36:40 +1000 Subject: [PATCH 4/5] Removed default export for cross-compatible ESM/CJS named exports. This is a nesesary breaking change. This is consistent with the graphql package, which only has named exports. --- README.md | 12 ++++++------ examples/index.js | 2 +- src/__tests__/http-test.js | 2 +- src/__tests__/usage-test.js | 2 +- src/index.js | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a7278a6b..addbd337 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Just mount `express-graphql` as a route handler: ```js const express = require('express'); -const graphqlHTTP = require('express-graphql'); +const { graphqlHTTP } = require('express-graphql'); const app = express(); @@ -38,7 +38,7 @@ Use `.get` or `.post` (or both) rather than `.use` to configure your route handl ```js const restify = require('restify'); -const graphqlHTTP = require('express-graphql'); +const { graphqlHTTP } = require('express-graphql'); const app = restify.createServer(); @@ -162,7 +162,7 @@ This example uses [`express-session`][] to provide GraphQL with the currently lo ```js const session = require('express-session'); -const graphqlHTTP = require('express-graphql'); +const { graphqlHTTP } = require('express-graphql'); const app = express(); @@ -207,7 +207,7 @@ This example illustrates adding the amount of time consumed by running the provided query, which could perhaps be used by your development tools. ```js -const graphqlHTTP = require('express-graphql'); +const { graphqlHTTP } = require('express-graphql'); const app = express(); @@ -273,9 +273,9 @@ running a GraphQL request. This function is used internally to handle the incoming request, you may use it directly for building other similar services. ```js -const graphqlHTTP = require('express-graphql'); +const { getGraphQLParams } = require('express-graphql'); -graphqlHTTP.getGraphQLParams(request).then(params => { +getGraphQLParams(request).then(params => { // do something... }) ``` diff --git a/examples/index.js b/examples/index.js index 1fe67583..11ebe70f 100644 --- a/examples/index.js +++ b/examples/index.js @@ -8,7 +8,7 @@ */ import express from 'express'; -import graphqlHTTP from '../src/'; +import { graphqlHTTP } from '../src/'; import { buildSchema } from 'graphql'; // Construct a schema, using GraphQL schema language diff --git a/src/__tests__/http-test.js b/src/__tests__/http-test.js index 05f4b5e5..bf451b64 100644 --- a/src/__tests__/http-test.js +++ b/src/__tests__/http-test.js @@ -30,7 +30,7 @@ import { GraphQLError, BREAK, } from 'graphql'; -import graphqlHTTP from '../'; +import { graphqlHTTP } from '../'; const QueryRootType = new GraphQLObjectType({ name: 'QueryRoot', diff --git a/src/__tests__/usage-test.js b/src/__tests__/usage-test.js index 4ec7842c..0ef29555 100644 --- a/src/__tests__/usage-test.js +++ b/src/__tests__/usage-test.js @@ -11,7 +11,7 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; import request from 'supertest'; import express from 'express'; -import graphqlHTTP from '../'; +import { graphqlHTTP } from '../'; describe('Useful errors when incorrectly used', () => { it('requires an option factory function', () => { diff --git a/src/index.js b/src/index.js index 13a35a0c..3fe33d18 100644 --- a/src/index.js +++ b/src/index.js @@ -138,7 +138,7 @@ type Middleware = (request: $Request, response: $Response) => Promise; * Middleware for express; takes an options object or function as input to * configure behavior, and returns an express middleware. */ -export default function graphqlHTTP(options: Options): Middleware { +export function graphqlHTTP(options: Options): Middleware { if (!options) { throw new Error('GraphQL middleware requires options.'); } From a5d02db55b4dc41823a8234a90ec4d148ccfe2c3 Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Mon, 7 May 2018 13:05:14 +1000 Subject: [PATCH 5/5] Update Node.js support to v6+. - Configured Travis to test on the latest stable Node.js version (v9-10+ were not being tested!), and the lowest supported version which is now v6. Removed unessesary versions in between. - Updated package.json engines field, which in turn updates transpilation via dynamic Babel preset-env config. --- .travis.yml | 4 +--- package.json | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 993b6a62..82d4b065 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,10 +2,8 @@ language: node_js # https://github.com/nodejs/LTS node_js: - - "8" - - "7" + - "node" - "6" - - "4" git: depth: 5 diff --git a/package.json b/package.json index 835a2d5c..55b78488 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "api" ], "engines": { - "node": ">=4" + "node": ">=6" }, "main": "dist/index", "module": "dist/index.mjs",