Skip to content

Commit 2bb7789

Browse files
committed
feat: add mjs build (es6 modules)
1 parent ec2da71 commit 2bb7789

File tree

6 files changed

+65
-13
lines changed

6 files changed

+65
-13
lines changed

.babelrc

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,45 @@
22
"plugins": [
33
"transform-object-rest-spread",
44
"transform-flow-strip-types",
5-
["transform-runtime", { "polyfill": false }]
6-
],
7-
"presets": [
8-
["env", {
9-
"targets": {
10-
"node": 4
11-
},
12-
}]
135
],
6+
"env": {
7+
"cjs": {
8+
"plugins": [
9+
"transform-class-properties",
10+
["transform-runtime", { "polyfill": false }]
11+
],
12+
"presets": [
13+
["env", {
14+
"targets": {
15+
"node": 4
16+
},
17+
}]
18+
],
19+
},
20+
"mjs": {
21+
"plugins": ["transform-class-properties"],
22+
"presets": [
23+
[
24+
"env",
25+
{
26+
"targets": {
27+
"node": "8.0.0"
28+
},
29+
"loose": true,
30+
"modules": false
31+
}
32+
]
33+
]
34+
},
35+
"test": {
36+
"plugins": ["transform-class-properties"],
37+
"presets": [
38+
["env", {
39+
"targets": {
40+
"node": "current"
41+
},
42+
}]
43+
]
44+
}
45+
}
1446
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
flow-typed
22
lib
3+
mjs

.flowconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.*/coverage/.*
33
.*/resources/.*
44
<PROJECT_ROOT>/lib/.*
5-
<PROJECT_ROOT>/dist/.*
5+
<PROJECT_ROOT>/mjs/.*
66
.*/node_modules/ajv.*
77
.*/node_modules/acorn.*
88
.*/node_modules/async.*

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ node_modules
4141
# Transpiled code
4242
/es
4343
/lib
44+
/mjs
4445
/__fixtures__
4546

4647
coverage

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
"version": "0.0.0-semantically-released",
44
"description": "Elastic search via GraphQL",
55
"files": [
6-
"lib"
6+
"lib",
7+
"mjs"
78
],
89
"main": "lib/index.js",
10+
"module": "mjs/index.mjs",
911
"repository": {
1012
"type": "git",
1113
"url": "https://github.com/nodkz/graphql-compose-elasticsearch.git"
@@ -34,6 +36,7 @@
3436
"babel-cli": "^6.26.0",
3537
"babel-eslint": "^8.2.5",
3638
"babel-jest": "^23.2.0",
39+
"babel-plugin-transform-class-properties": "^6.24.1",
3740
"babel-plugin-transform-flow-strip-types": "^6.22.0",
3841
"babel-plugin-transform-object-rest-spread": "^6.26.0",
3942
"babel-plugin-transform-runtime": "^6.23.0",
@@ -69,9 +72,11 @@
6972
]
7073
},
7174
"scripts": {
72-
"build": "npm-run-all build:*",
73-
"build:lib": "rimraf lib && babel src --ignore __tests__,__mocks__ -d lib",
74-
"build:flow": "find ./src -name '*.js' -not -path '*/__*' | while read filepath; do cp $filepath `echo $filepath | sed 's/\\/src\\//\\/lib\\//g'`.flow; done",
75+
"build": "npm run build-cjs && npm run build-mjs",
76+
"build-cjs": "rimraf lib && BABEL_ENV=cjs babel src --ignore __tests__,__mocks__ -d lib && COPY_TO_FOLDER=lib npm run build-flow",
77+
"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",
78+
"build-mjs-rename": "find ./mjs -name \"*.js\" -exec bash -c 'mv \"$1\" \"${1%.js}\".mjs' - '{}' \\;",
79+
"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",
7580
"dev": "npm run demo1",
7681
"demo1": "yarn demo1:seed && nodemon -e js --ignore *test* --exec ./node_modules/.bin/babel-node ./examples/elastic50/index.js",
7782
"demo1:seed": "./node_modules/.bin/babel-node ./examples/elastic50/seedData.js",

yarn.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,10 @@ babel-plugin-syntax-async-functions@^6.8.0:
749749
version "6.13.0"
750750
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95"
751751

752+
babel-plugin-syntax-class-properties@^6.8.0:
753+
version "6.13.0"
754+
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-class-properties/-/babel-plugin-syntax-class-properties-6.13.0.tgz#d7eb23b79a317f8543962c505b827c7d6cac27de"
755+
752756
babel-plugin-syntax-exponentiation-operator@^6.8.0:
753757
version "6.13.0"
754758
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-exponentiation-operator/-/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz#9ee7e8337290da95288201a6a57f4170317830de"
@@ -773,6 +777,15 @@ babel-plugin-transform-async-to-generator@^6.22.0:
773777
babel-plugin-syntax-async-functions "^6.8.0"
774778
babel-runtime "^6.22.0"
775779

780+
babel-plugin-transform-class-properties@^6.24.1:
781+
version "6.24.1"
782+
resolved "https://registry.yarnpkg.com/babel-plugin-transform-class-properties/-/babel-plugin-transform-class-properties-6.24.1.tgz#6a79763ea61d33d36f37b611aa9def81a81b46ac"
783+
dependencies:
784+
babel-helper-function-name "^6.24.1"
785+
babel-plugin-syntax-class-properties "^6.8.0"
786+
babel-runtime "^6.22.0"
787+
babel-template "^6.24.1"
788+
776789
babel-plugin-transform-es2015-arrow-functions@^6.22.0:
777790
version "6.22.0"
778791
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-arrow-functions/-/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz#452692cb711d5f79dc7f85e440ce41b9f244d221"

0 commit comments

Comments
 (0)