Skip to content

Commit ccb5e8a

Browse files
committed
ESM CJS + Jest (#1322)
1 parent 9fd4060 commit ccb5e8a

30 files changed

+1227
-1195
lines changed

.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ parserOptions:
44
env:
55
es6: true
66
node: true
7+
jest: true
78
plugins:
89
- import
910

.travis.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,27 @@
11
language: node_js
22
node_js:
3-
- "13"
43
- "12"
54
- "10"
65

76
env:
8-
- GRAPHQL_VERSION='0.12'
97
- GRAPHQL_VERSION='0.13'
10-
- GRAPHQL_VERSION='14.0'
11-
- GRAPHQL_VERSION='14.1'
12-
- GRAPHQL_VERSION='14.2'
13-
- GRAPHQL_VERSION='14.3'
14-
- GRAPHQL_VERSION='14.4'
15-
- GRAPHQL_VERSION='14.5'
16-
- GRAPHQL_VERSION='14.6'
8+
- GRAPHQL_VERSION='latest'
179
- GRAPHQL_VERSION='rc'
1810

1911
install:
2012
- npm config set spin=false
2113
- npm install
2214

2315
script:
24-
- node_version=$(node -v); if [[ ${node_version:1:2} == "13" && $GRAPHQL_VERSION == "14.6" ]]; then
16+
- if [[ $GRAPHQL_VERSION == "latest" ]]; then
2517
npm run lint;
2618
fi
27-
- node_version=$(node -v); if [[ ${node_version:1:2} == "13" && $GRAPHQL_VERSION == "14.6" ]]; then
28-
npm run prettier:check;
19+
- if [[ $GRAPHQL_VERSION == "latest" ]]; then
20+
npm run format:check;
2921
fi
3022
- npm run compile
3123
- npm install graphql@$GRAPHQL_VERSION
32-
- npm run testonly:cover
33-
34-
after_success:
35-
- npm run coverage
24+
- npm run test
3625

3726
# Allow Travis tests to run in containers.
3827
sudo: false

docs/package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jest.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { resolve } = require('path');
2+
const CI = !!process.env.CI;
3+
4+
module.exports = {
5+
transform: { '^.+\\.tsx?$': 'ts-jest' },
6+
testEnvironment: 'node',
7+
rootDir: process.cwd(),
8+
globals: {
9+
'ts-jest': {
10+
diagnostics: false,
11+
tsConfig: 'tsconfig.json'
12+
}
13+
},
14+
restoreMocks: true,
15+
reporters: ['default'],
16+
modulePathIgnorePatterns: ['dist'],
17+
collectCoverage: CI,
18+
collectCoverageFrom: ['src', '!src/test']
19+
};

package.json

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,29 @@
22
"name": "graphql-tools",
33
"version": "5.0.0-alpha.0",
44
"description": "Useful tools to create and manipulate GraphQL schemas.",
5-
"main": "dist/index.js",
5+
"sideEffects": false,
6+
"main": "dist/index.cjs.js",
7+
"module": "dist/index.esm.js",
68
"types": "dist/index.d.ts",
9+
"typings": "dist/index.d.ts",
10+
"typescript": {
11+
"definition": "dist/index.d.ts"
12+
},
713
"files": [
814
"/dist",
915
"!/dist/test"
1016
],
11-
"sideEffects": false,
1217
"scripts": {
1318
"clean": "rimraf dist",
14-
"build": "npm run compile",
1519
"precompile": "npm run clean",
16-
"compile": "tsc",
17-
"pretest": "npm run clean && npm run compile",
18-
"test": "npm run testonly",
19-
"posttest": "npm run lint && npm run prettier:check",
20+
"compile": "rollup -c rollup.config.js",
21+
"test": "jest",
2022
"lint": "eslint --ext .js,.ts src",
2123
"lint:watch": "esw --watch --cache --ext .js,.ts src",
22-
"watch": "tsc -w",
23-
"testonly": "mocha --reporter spec --full-trace ./dist/test/**.js --require source-map-support/register",
24-
"testonly:cover": "nyc npm run testonly",
25-
"testonly:watch": "mocha -w --reporter spec --full-trace ./dist/test/**.js --require source-map-support/register",
26-
"coverage": "nyc report --reporter=text-lcov | coveralls",
24+
"watch": "npm run compile -- --watch",
2725
"prepublishOnly": "npm run compile",
28-
"prettier": "prettier --trailing-comma all --single-quote --write src/**/*.ts",
29-
"prettier:check": "prettier --trailing-comma all --single-quote --check src/**/*.ts"
26+
"format": "prettier --write src/**/*.ts",
27+
"format:check": "prettier --check src/**/*.ts"
3028
},
3129
"repository": {
3230
"type": "git",
@@ -45,9 +43,9 @@
4543
"author": "Jonas Helfer <[email protected]>",
4644
"license": "MIT",
4745
"bugs": {
48-
"url": "https://github.com/apollostack/graphql-tools/issues"
46+
"url": "https://github.com/apollographql/graphql-tools/issues"
4947
},
50-
"homepage": "https://github.com/apollostack/graphql-tools#readme",
48+
"homepage": "https://github.com/apollographql/graphql-tools#readme",
5149
"dependencies": {
5250
"apollo-link": "^1.2.13",
5351
"apollo-link-http-common": "^0.2.15",
@@ -63,22 +61,20 @@
6361
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0-rc"
6462
},
6563
"devDependencies": {
66-
"@types/chai": "4.2.11",
64+
"@rollup/plugin-node-resolve": "7.1.1",
6765
"@types/dateformat": "3.0.1",
6866
"@types/express": "4.17.3",
6967
"@types/extract-files": "3.1.0",
7068
"@types/graphql-type-json": "0.3.2",
7169
"@types/graphql-upload": "8.0.3",
72-
"@types/mocha": "7.0.2",
70+
"@types/jest": "25.1.4",
7371
"@types/node": "13.9.3",
7472
"@types/node-fetch": "2.5.5",
7573
"@types/uuid": "7.0.2",
7674
"@typescript-eslint/eslint-plugin": "2.25.0",
7775
"@typescript-eslint/parser": "2.25.0",
7876
"babel-eslint": "10.1.0",
7977
"body-parser": "1.19.0",
80-
"chai": "4.2.0",
81-
"coveralls": "3.0.11",
8278
"dataloader": "2.0.0",
8379
"dateformat": "3.0.3",
8480
"eslint": "6.8.0",
@@ -90,12 +86,18 @@
9086
"graphql-subscriptions": "1.1.0",
9187
"graphql-type-json": "0.3.1",
9288
"graphql-upload": "10.0.0",
93-
"mocha": "7.1.1",
94-
"nyc": "15.0.0",
89+
"jest": "25.2.4",
9590
"prettier": "2.0.2",
9691
"rimraf": "3.0.2",
97-
"source-map-support": "0.5.16",
92+
"rollup": "2.3.1",
93+
"rollup-plugin-auto-external": "2.0.0",
94+
"rollup-plugin-typescript2": "0.27.0",
95+
"ts-jest": "25.3.0",
9896
"typescript": "3.8.3",
9997
"zen-observable-ts": "0.8.20"
98+
},
99+
"prettier": {
100+
"singleQuote": true,
101+
"trailingComma": "all"
100102
}
101103
}

rollup.config.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import autoExternal from 'rollup-plugin-auto-external';
2+
import resolveNode from '@rollup/plugin-node-resolve';
3+
import rollupTypescript from 'rollup-plugin-typescript2';
4+
5+
const commonOutputOptions = {
6+
preferConst: true,
7+
sourcemap: true
8+
};
9+
10+
export default {
11+
input: 'src/index.ts',
12+
plugins: [
13+
resolveNode(),
14+
autoExternal({ builtins: true, dependencies: true, peerDependencies: true }),
15+
rollupTypescript()
16+
],
17+
output: [
18+
{
19+
...commonOutputOptions,
20+
file: 'dist/index.cjs.js',
21+
format: 'cjs'
22+
},
23+
{
24+
...commonOutputOptions,
25+
file: 'dist/index.esm.js',
26+
format: 'esm'
27+
}
28+
]
29+
};

0 commit comments

Comments
 (0)