From 65169772f8623b0169f090b06f06e79f8448f293 Mon Sep 17 00:00:00 2001 From: nodkz Date: Tue, 26 Jun 2018 20:37:16 +0600 Subject: [PATCH] feat: add mjs build (es6 modules) --- .babelrc | 45 +++++++++++++++++++++++++++++++++++++-------- .eslintignore | 1 + .flowconfig | 2 +- .gitignore | 1 + package.json | 14 +++++++++----- yarn.lock | 6 +++--- 6 files changed, 52 insertions(+), 17 deletions(-) diff --git a/.babelrc b/.babelrc index 16ab913..08ee61c 100644 --- a/.babelrc +++ b/.babelrc @@ -2,13 +2,42 @@ "plugins": [ "transform-object-rest-spread", "transform-flow-strip-types", - ["transform-runtime", { "polyfill": false }] - ], - "presets": [ - ["env", { - "targets": { - "node": 4 - }, - }] ], + "env": { + "cjs": { + "plugins": [ + ["transform-runtime", { "polyfill": false }] + ], + "presets": [ + ["env", { + "targets": { + "node": 4 + }, + }] + ], + }, + "mjs": { + "presets": [ + [ + "env", + { + "targets": { + "node": "8.0.0" + }, + "loose": true, + "modules": false + } + ] + ] + }, + "test": { + "presets": [ + ["env", { + "targets": { + "node": "current" + }, + }] + ] + } + } } diff --git a/.eslintignore b/.eslintignore index 27ee193..06eaaef 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ lib/* flow-typed/* +mjs/* diff --git a/.flowconfig b/.flowconfig index a447c39..3c3012e 100644 --- a/.flowconfig +++ b/.flowconfig @@ -2,7 +2,7 @@ .*/coverage/.* .*/resources/.* /lib/.* -/dist/.* +/mjs/.* .*/node_modules/ajv.* .*/node_modules/acorn.* .*/node_modules/async.* diff --git a/.gitignore b/.gitignore index 7eb80f0..47d2640 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,7 @@ node_modules # Transpiled code /es /lib +/mjs coverage .nyc_output diff --git a/package.json b/package.json index 1ab2781..088dbe0 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,11 @@ "version": "0.0.0-semantically-released", "description": "Plugin for `graphql-compose` which wraps graphql types with Relay specific logic.", "files": [ - "lib" + "lib", + "mjs" ], "main": "lib/index.js", + "module": "mjs/index.mjs", "repository": { "type": "git", "url": "https://github.com/graphql-compose/graphql-compose-relay.git" @@ -41,7 +43,7 @@ "eslint-plugin-prettier": "^2.6.1", "flow-bin": "^0.75.0", "graphql": "0.13.2", - "graphql-compose": "^4.4.0", + "graphql-compose": "^4.4.1", "jest": "^23.2.0", "prettier": "^1.13.6", "rimraf": "^2.6.2", @@ -61,9 +63,11 @@ ] }, "scripts": { - "build": "npm run build-cjs && npm run build-flow", - "build-cjs": "rimraf lib && babel src --ignore __tests__,__mocks__ -d lib", - "build-flow": "find ./src -name '*.js' -not -path '*/__*' | while read filepath; do cp $filepath `echo $filepath | sed 's/\\/src\\//\\/lib\\//g'`.flow; done", + "build": "npm run build-cjs && npm run build-mjs", + "build-cjs": "rimraf lib && babel src --ignore __tests__,__mocks__ -d lib && COPY_TO_FOLDER=lib npm run build-flow", + "build-mjs": "rimraf mjs && BABEL_ENV=mjs babel src --ignore __tests__,__mocks__ -d mjs && yarn build-mjs-rename && COPY_TO_FOLDER=mjs npm run build-flow", + "build-mjs-rename": "find ./mjs -name \"*.js\" -exec bash -c 'mv \"$1\" \"${1%.js}\".mjs' - '{}' \\;", + "build-flow": "find ./src -name '*.js' -not -path '*/__*' | while read filepath; do cp $filepath `echo ./${COPY_TO_FOLDER:-lib}$filepath | sed 's/.\\/src\\//\\//g'`.flow; done", "watch": "jest --watch", "coverage": "jest --coverage", "lint": "eslint --ext .js ./src", diff --git a/yarn.lock b/yarn.lock index 79c194d..3dcf5db 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2397,9 +2397,9 @@ graceful-fs@^4.1.4: version "4.1.9" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.9.tgz#baacba37d19d11f9d146d3578bc99958c3787e29" -graphql-compose@^4.4.0: - version "4.4.0" - resolved "https://registry.yarnpkg.com/graphql-compose/-/graphql-compose-4.4.0.tgz#459045017496d63c00051e23d850907bfbf5cede" +graphql-compose@^4.4.1: + version "4.4.1" + resolved "https://registry.yarnpkg.com/graphql-compose/-/graphql-compose-4.4.1.tgz#2f801bb8e70e8601c21a2e52b629a21c6aba35db" dependencies: babel-runtime "^6.26.0" graphql-type-json "^0.2.1"