From b3d67eed5cf39e12ad29093025186014d7949c9d Mon Sep 17 00:00:00 2001 From: nodkz Date: Tue, 26 Jun 2018 21:20:38 +0600 Subject: [PATCH] feat: add mjs build (es6 modules) --- .babelrc | 16 +++++++++++++++- .eslintignore | 1 + .flowconfig | 2 +- .gitignore | 1 + package.json | 10 +++++++--- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.babelrc b/.babelrc index 9070eb94..d2b9ce12 100644 --- a/.babelrc +++ b/.babelrc @@ -4,7 +4,7 @@ "transform-flow-strip-types", ], "env": { - "lib": { + "cjs": { "plugins": [ ["transform-runtime", { "polyfill": false }] ], @@ -16,6 +16,20 @@ }] ] }, + "mjs": { + "presets": [ + [ + "env", + { + "targets": { + "node": "8.0.0" + }, + "loose": true, + "modules": false + } + ] + ] + }, "es": { }, "node8": { diff --git a/.eslintignore b/.eslintignore index 0345275d..bf6000d6 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,5 @@ lib/* es/* +mjs/* node8/* flow-typed diff --git a/.flowconfig b/.flowconfig index 6cd402ff..b69bf4a7 100644 --- a/.flowconfig +++ b/.flowconfig @@ -4,7 +4,7 @@ /lib/.* /es/.* /node8/.* -/dist/.* +/mjs/.* .*/node_modules/ajv.* .*/node_modules/acorn.* .*/node_modules/async.* diff --git a/.gitignore b/.gitignore index 106193a6..9b6781c4 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,7 @@ node_modules /es /lib /node8 +/mjs coverage .nyc_output diff --git a/package.json b/package.json index 93c714ff..ca652e81 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,11 @@ "files": [ "lib", "node8", - "es" + "es", + "mjs" ], "main": "lib/index.js", + "module": "mjs/index.mjs", "repository": { "type": "git", "url": "https://github.com/graphql-compose/graphql-compose-mongoose.git" @@ -76,10 +78,12 @@ ] }, "scripts": { - "build": "npm run build-lib && npm run build-es && npm run build-node8", - "build-lib": "rimraf lib && BABEL_ENV=lib babel src --ignore __tests__,__mocks__ -d lib && COPY_TO_FOLDER=lib npm run build-flow", + "build": "npm run build-lib && npm run build-mjs && npm run build-es && npm run build-node8", + "build-lib": "rimraf lib && BABEL_ENV=cjs babel src --ignore __tests__,__mocks__ -d lib && COPY_TO_FOLDER=lib npm run build-flow", "build-es": "rimraf es && BABEL_ENV=es babel src --ignore __tests__,__mocks__ -d es && COPY_TO_FOLDER=es npm run build-flow", "build-node8": "rimraf node8 && BABEL_ENV=node8 babel src --ignore __tests__,__mocks__ -d node8 && COPY_TO_FOLDER=node8 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": "echo `$1` && 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 --maxWorkers 2",