Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESM CJS + Jest #1320

Merged
merged 5 commits into from Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.yml
Expand Up @@ -4,6 +4,7 @@ parserOptions:
env:
es6: true
node: true
jest: true
plugins:
- import

Expand Down
21 changes: 5 additions & 16 deletions .travis.yml
@@ -1,38 +1,27 @@
language: node_js
node_js:
- "13"
- "12"
- "10"

env:
- GRAPHQL_VERSION='0.12'
- GRAPHQL_VERSION='0.13'
- GRAPHQL_VERSION='14.0'
- GRAPHQL_VERSION='14.1'
- GRAPHQL_VERSION='14.2'
- GRAPHQL_VERSION='14.3'
- GRAPHQL_VERSION='14.4'
- GRAPHQL_VERSION='14.5'
- GRAPHQL_VERSION='14.6'
- GRAPHQL_VERSION='latest'
- GRAPHQL_VERSION='rc'

install:
- npm config set spin=false
- npm install

script:
- node_version=$(node -v); if [[ ${node_version:1:2} == "13" && $GRAPHQL_VERSION == "14.6" ]]; then
- if [[ $GRAPHQL_VERSION == "latest" ]]; then
npm run lint;
fi
- node_version=$(node -v); if [[ ${node_version:1:2} == "13" && $GRAPHQL_VERSION == "14.6" ]]; then
npm run prettier:check;
- if [[ $GRAPHQL_VERSION == "latest" ]]; then
npm run format:check;
fi
- npm run compile
- npm install graphql@$GRAPHQL_VERSION
- npm run testonly:cover

after_success:
- npm run coverage
- npm run test

# Allow Travis tests to run in containers.
sudo: false
19 changes: 19 additions & 0 deletions jest.config.js
@@ -0,0 +1,19 @@
const { resolve } = require('path');
const CI = !!process.env.CI;

module.exports = {
transform: { '^.+\\.tsx?$': 'ts-jest' },
testEnvironment: 'node',
rootDir: process.cwd(),
globals: {
'ts-jest': {
diagnostics: false,
tsConfig: 'tsconfig.json'
}
},
restoreMocks: true,
reporters: ['default'],
modulePathIgnorePatterns: ['dist'],
collectCoverage: CI,
collectCoverageFrom: ['src', '!src/test']
};
48 changes: 25 additions & 23 deletions package.json
Expand Up @@ -2,31 +2,29 @@
"name": "graphql-tools",
"version": "5.0.0-alpha.0",
"description": "Useful tools to create and manipulate GraphQL schemas.",
"main": "dist/index.js",
"sideEffects": false,
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
},
"files": [
"/dist",
"!/dist/test"
],
"sideEffects": false,
"scripts": {
"clean": "rimraf dist",
"build": "npm run compile",
"precompile": "npm run clean",
"compile": "tsc",
"pretest": "npm run clean && npm run compile",
"test": "npm run testonly",
"posttest": "npm run lint && npm run prettier:check",
"compile": "rollup -c rollup.config.js",
"test": "jest",
"lint": "eslint --ext .js,.ts src",
"lint:watch": "esw --watch --cache --ext .js,.ts src",
"watch": "tsc -w",
"testonly": "mocha --reporter spec --full-trace ./dist/test/**.js --require source-map-support/register",
"testonly:cover": "nyc npm run testonly",
"testonly:watch": "mocha -w --reporter spec --full-trace ./dist/test/**.js --require source-map-support/register",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"watch": "npm run compile -- --watch",
"prepublishOnly": "npm run compile",
"prettier": "prettier --trailing-comma all --single-quote --write src/**/*.ts",
"prettier:check": "prettier --trailing-comma all --single-quote --check src/**/*.ts"
"format": "prettier --write src/**/*.ts",
"format:check": "prettier --check src/**/*.ts"
},
"repository": {
"type": "git",
Expand All @@ -45,9 +43,9 @@
"author": "Jonas Helfer <jonas@helfer.email>",
"license": "MIT",
"bugs": {
"url": "https://github.com/apollostack/graphql-tools/issues"
"url": "https://github.com/apollographql/graphql-tools/issues"
},
"homepage": "https://github.com/apollostack/graphql-tools#readme",
"homepage": "https://github.com/apollographql/graphql-tools#readme",
"dependencies": {
"apollo-link": "^1.2.13",
"apollo-link-http-common": "^0.2.15",
Expand All @@ -63,22 +61,20 @@
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0-rc"
},
"devDependencies": {
"@types/chai": "4.2.11",
"@rollup/plugin-node-resolve": "7.1.1",
"@types/dateformat": "3.0.1",
"@types/express": "4.17.3",
"@types/extract-files": "3.1.0",
"@types/graphql-type-json": "0.3.2",
"@types/graphql-upload": "8.0.3",
"@types/mocha": "7.0.2",
"@types/jest": "25.1.4",
"@types/node": "13.9.3",
"@types/node-fetch": "2.5.5",
"@types/uuid": "7.0.2",
"@typescript-eslint/eslint-plugin": "2.25.0",
"@typescript-eslint/parser": "2.25.0",
"babel-eslint": "10.1.0",
"body-parser": "1.19.0",
"chai": "4.2.0",
"coveralls": "3.0.11",
"dataloader": "2.0.0",
"dateformat": "3.0.3",
"eslint": "6.8.0",
Expand All @@ -90,12 +86,18 @@
"graphql-subscriptions": "1.1.0",
"graphql-type-json": "0.3.1",
"graphql-upload": "10.0.0",
"mocha": "7.1.1",
"nyc": "15.0.0",
"jest": "25.2.4",
"prettier": "2.0.2",
"rimraf": "3.0.2",
"source-map-support": "0.5.16",
"rollup": "2.3.1",
"rollup-plugin-auto-external": "2.0.0",
"rollup-plugin-typescript2": "0.27.0",
"ts-jest": "25.3.0",
"typescript": "3.8.3",
"zen-observable-ts": "0.8.20"
},
"prettier": {
"singleQuote": true,
"trailingComma": "all"
}
}
29 changes: 29 additions & 0 deletions rollup.config.js
@@ -0,0 +1,29 @@
import autoExternal from 'rollup-plugin-auto-external';
import resolveNode from '@rollup/plugin-node-resolve';
import rollupTypescript from 'rollup-plugin-typescript2';

const commonOutputOptions = {
preferConst: true,
sourcemap: true
};

export default {
input: 'src/index.ts',
plugins: [
resolveNode(),
autoExternal({ builtins: true, dependencies: true, peerDependencies: true }),
rollupTypescript()
],
output: [
{
...commonOutputOptions,
file: 'dist/index.cjs.js',
format: 'cjs'
},
{
...commonOutputOptions,
file: 'dist/index.esm.js',
format: 'esm'
}
]
};