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

Prepare for concurrently developing in TS and Flow #2139

Closed
wants to merge 13 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .browserslistrc
@@ -1,4 +1,4 @@
node 6
node 8
ie 9
ios 9
last 2 chrome versions
Expand Down
54 changes: 3 additions & 51 deletions .eslintrc.yml → .eslintrc.base.yml
@@ -1,59 +1,11 @@
parser: babel-eslint
parserOptions:
sourceType: module
env:
es6: true
node: true
plugins:
- flowtype

parserOptions:
sourceType: module
rules:
# `eslint-plugin-flowtype` rule list based on `v3.12.x`
# https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype

flowtype/array-style-complex-type: [error, verbose]
flowtype/array-style-simple-type: [error, verbose]
flowtype/define-flow-type: error
flowtype/newline-after-flow-annotation: [error, always]
flowtype/no-dupe-keys: error
flowtype/no-existential-type: off # checked by Flow
flowtype/no-flow-fix-me-comments: off # TODO
flowtype/no-mixed: off
flowtype/no-mutable-array: off
flowtype/no-primitive-constructor-types: error
flowtype/no-types-missing-file-annotation: error
flowtype/no-unused-expressions: off
flowtype/no-weak-types: [error, { any: false }]
flowtype/require-compound-type-alias: off
flowtype/require-exact-type: off # TODO
flowtype/require-inexact-type: off # checked by Flow
flowtype/require-parameter-type: off
flowtype/require-readonly-react-props: off
flowtype/require-return-type: off
flowtype/require-types-at-top: off
flowtype/require-valid-file-annotation:
[error, always, { annotationStyle: line, strict: true }]
flowtype/require-variable-type: off
flowtype/sort-keys: off
flowtype/spread-exact-type: off
flowtype/type-id-match: [error, '^[A-Z]']
flowtype/type-import-style: [error, identifier, { ignoreTypeDefault: true }]
flowtype/use-flow-type: error

# Bellow rules are disabled because coflicts with Prettier, see:
# https://github.com/prettier/eslint-config-prettier/blob/master/flowtype.js
flowtype/boolean-style: off
flowtype/delimiter-dangle: off
flowtype/generic-spacing: off
flowtype/object-type-delimiter: off
flowtype/semi: off
flowtype/space-after-type-colon: off
flowtype/space-before-generic-bracket: off
flowtype/space-before-type-colon: off
flowtype/union-intersection-spacing: off

##################################################
# ESLint builtin rules list based on `v5.16.x`
# ESLint builtin rules list based on `v6.1.x`
##################################################

# Possible Errors
Expand Down
49 changes: 49 additions & 0 deletions .eslintrc.flow.yml
@@ -0,0 +1,49 @@
extends: .eslintrc.base.yml
parser: babel-eslint
plugins:
- flowtype
rules:
# `eslint-plugin-flowtype` rule list based on `v4.2.x`
# https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype

flowtype/array-style-complex-type: [error, verbose]
flowtype/array-style-simple-type: [error, verbose]
flowtype/define-flow-type: error
flowtype/newline-after-flow-annotation: [error, always]
flowtype/no-dupe-keys: error
flowtype/no-existential-type: off # checked by Flow
flowtype/no-flow-fix-me-comments: off # TODO
flowtype/no-mixed: off
flowtype/no-mutable-array: off
flowtype/no-primitive-constructor-types: error
flowtype/no-types-missing-file-annotation: error
flowtype/no-unused-expressions: off
flowtype/no-weak-types: [error, { any: false }]
flowtype/require-compound-type-alias: off
flowtype/require-exact-type: off # TODO
flowtype/require-indexer-name: error
flowtype/require-inexact-type: off # checked by Flow
flowtype/require-parameter-type: off
flowtype/require-readonly-react-props: off
flowtype/require-return-type: off
flowtype/require-types-at-top: off
flowtype/require-valid-file-annotation:
[error, always, { annotationStyle: line, strict: true }]
flowtype/require-variable-type: off
flowtype/sort-keys: off
flowtype/spread-exact-type: off
flowtype/type-id-match: [error, '^[A-Z]']
flowtype/type-import-style: [error, identifier, { ignoreTypeDefault: true }]
flowtype/use-flow-type: error

# Bellow rules are disabled because coflicts with Prettier, see:
# https://github.com/prettier/eslint-config-prettier/blob/master/flowtype.js
flowtype/boolean-style: off
flowtype/delimiter-dangle: off
flowtype/generic-spacing: off
flowtype/object-type-delimiter: off
flowtype/semi: off
flowtype/space-after-type-colon: off
flowtype/space-before-generic-bracket: off
flowtype/space-before-type-colon: off
flowtype/union-intersection-spacing: off
20 changes: 20 additions & 0 deletions .eslintrc.ts.yml
@@ -0,0 +1,20 @@
extends:
[
.eslintrc.base.yml,
plugin:@typescript-eslint/eslint-recommended,
plugin:@typescript-eslint/recommended,
plugin:@typescript-eslint/recommended-requiring-type-checking,
]
parser: '@typescript-eslint/parser'
parserOptions:
'project': './tsconfig.json'
plugins: ['@typescript-eslint']
rules:
'no-useless-constructor': 'off'
'@typescript-eslint/no-useless-constructor': 'error'
'@typescript-eslint/no-explicit-any': 'off'

overrides:
- files: '**/*.d.ts'
rules:
'@typescript-eslint/no-unused-vars': 'off'
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -13,3 +13,4 @@ coverage
dist
benchmarkDist
npm
ts-build
1 change: 1 addition & 0 deletions .mocharc.yml
Expand Up @@ -3,3 +3,4 @@ check-leaks: true
require:
- '@babel/register'
- '@babel/polyfill'
- 'ts-node/register'
1 change: 1 addition & 0 deletions .nycrc.yml
Expand Up @@ -3,6 +3,7 @@ include:
exclude:
- 'src/polyfills'
clean: true
extends: '@istanbuljs/nyc-config-typescript'
temp-directory: 'coverage/tests'
report-dir: 'coverage/tests'
skip-full: true
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -8,7 +8,6 @@ node_js:
- '12'
- '10'
- '8'
- '6'

script: |
if [[ "$(node -pe process.version)" == v10.* ]]; then # Is latest LTS?
Expand Down
25 changes: 25 additions & 0 deletions README.md
Expand Up @@ -138,3 +138,28 @@ Changes are tracked as [GitHub releases](https://github.com/graphql/graphql-js/r
### License

GraphQL.js is [MIT-licensed](https://github.com/graphql/graphql-js/blob/master/LICENSE).

## TypeScript definition files

We used `*.d.ts` files from [DefinetlyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/54712a7e28090c5b1253b746d1878003c954f3ff/types/graphql) as the basis for our TypeScript conversion in `v15.0.0`. Big thanks to:

- TonyYang https://github.com/TonyPythoneer
- Caleb Meredith https://github.com/calebmer
- Dominic Watson https://github.com/intellix
- Firede https://github.com/firede
- Kepennar https://github.com/kepennar
- Mikhail Novikov https://github.com/freiksenet
- Ivan Goncharov https://github.com/IvanGoncharov
- Hagai Cohen https://github.com/DxCx
- Ricardo Portugal https://github.com/rportugal
- Tim Griesser https://github.com/tgriesser
- Dylan Stewart https://github.com/dyst5422
- Alessio Dionisi https://github.com/adnsio
- Divyendu Singh https://github.com/divyenduz
- Brad Zacher https://github.com/bradzacher
- Curtis Layne https://github.com/clayne11
- Jonathan Cardoso https://github.com/JCMais
- Pavel Lang https://github.com/langpavel
- Mark Caudill https://github.com/mc0
- Martijn Walraven https://github.com/martijnwalraven
- Jed Mao https://github.com/jedmao
42 changes: 28 additions & 14 deletions package.json
Expand Up @@ -21,21 +21,25 @@
"graphql-js"
],
"engines": {
"node": ">= 6.x"
"node": ">= 8.x"
},
"scripts": {
"test": "npm run prettier:check && npm run lint && npm run check && npm run testonly && npm run check:ts",
"test:ci": "yarn check --integrity && npm run prettier:check && npm run lint -- --no-cache && npm run check && npm run testonly:cover && npm run check:ts && npm run build",
"testonly": "mocha --full-trace src/**/__tests__/**/*-test.js",
"test": "npm run prettier:check && npm run lint && npm run check && npm run testonly",
"test:ci": "yarn check --integrity && npm run prettier:check && npm run lint -- --no-cache && npm run check && npm run testonly:cover && npm run build",
"testonly": "mocha --full-trace src/**/__tests__/**/*-test.{ts,js}",
"testonly:cover": "nyc npm run testonly",
"lint": "eslint --cache --report-unused-disable-directives src resources",
"lint": "npm run lint:flow && npm run lint:ts",
"lint:flow": "eslint -c .eslintrc.flow.yml --cache --report-unused-disable-directives src resources",
"lint:ts": "eslint -c .eslintrc.ts.yml --cache --report-unused-disable-directives src --ext .ts",
"benchmark": "node --noconcurrent_sweeping --expose-gc --predictable ./resources/benchmark.js",
"prettier": "prettier --ignore-path .gitignore --write --list-different \"**/*.{js,ts,md,json,yml}\"",
"prettier:check": "prettier --ignore-path .gitignore --check \"**/*.{js,ts,md,json,yml}\"",
"check": "flow check",
"check:ts": "dtslint tstypes",
"prettier": "prettier --ignore-path .gitignore --write --list-different \"**/*.{js,ts,md,json,yml,flow}\"",
"prettier:check": "prettier --ignore-path .gitignore --check \"**/*.{js,ts,md,json,yml,flow}\"",
"check": "npm run check:flow && npm run check:ts && npm run check:dts",
"check:flow": "flow check",
"check:ts": "tsc",
"check:dts": "dtslint src",
"check:cover": "node resources/check-cover.js && nyc report --nycrc-path .nycflowrc.yml",
"build": "node resources/build.js",
"build": "tsc -b tsconfig.build.json && node resources/build.js",
"changelog": "node resources/gen-changelog.js",
"preversion": ". ./resources/checkgit.sh",
"version": "node resources/gen-version.js && npm test && git add src/version.js",
Expand All @@ -50,14 +54,24 @@
"@babel/polyfill": "7.4.4",
"@babel/preset-env": "7.5.5",
"@babel/register": "7.5.5",
"@istanbuljs/nyc-config-typescript": "^0.1.3",
"@types/chai": "^4.2.0",
"@types/mocha": "^5.2.7",
"@types/node": "^12.7.2",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"babel-eslint": "10.0.2",
"chai": "4.2.0",
"dtslint": "^0.9.2",
"eslint": "5.16.0",
"eslint-plugin-flowtype": "3.12.1",
"flow-bin": "0.106.0",
"eslint": "6.1.0",
"eslint-plugin-flowtype": "4.2.0",
"eslint-plugin-typescript": "^0.14.0",
"flow-bin": "0.106.1",
"mocha": "6.2.0",
"nyc": "14.1.1",
"prettier": "1.18.2"
"prettier": "1.18.2",
"source-map-support": "^0.5.13",
"ts-node": "^8.3.0",
"typescript": "^3.5.3"
}
}
32 changes: 23 additions & 9 deletions resources/build.js
Expand Up @@ -22,19 +22,25 @@ if (require.main === module) {
copyFile('./LICENSE', './dist/LICENSE');
copyFile('./README.md', './dist/README.md');

const srcFiles = readdirRecursive('./src', { ignoreDir: /^__.*__$/ });
for (const filepath of srcFiles) {
const tsArtifacts = readdirRecursive('./ts-build', { ignoreDir: /^__.*__$/ });
for (const filepath of tsArtifacts) {
if (filepath.endsWith('.js')) {
buildJSFile(filepath);
buildTSEmittedJSFile(filepath);
} else if (filepath.endsWith('.d.ts')) {
const srcPath = path.join('./ts-build', filepath);
const destPath = path.join('./dist', filepath);
copyFile(srcPath, destPath);
}
}
rmdirRecursive('./ts-build');

const tsFiles = readdirRecursive('./tstypes', { ignoreDir: /^__.*__$/ });
for (const filepath of tsFiles) {
if (filepath.endsWith('.d.ts')) {
const srcPath = path.join('./tstypes', filepath);
const srcFiles = readdirRecursive('./src', { ignoreDir: /^__.*__$/ });
for (const filepath of srcFiles) {
if (filepath.endsWith('.js')) {
buildFlowFile(filepath);
} else if (filepath.endsWith('.js.flow') || filepath.endsWith('.d.ts')) {
const srcPath = path.join('./src', filepath);
const destPath = path.join('./dist', filepath);

copyFile(srcPath, destPath);
}
}
Expand Down Expand Up @@ -99,7 +105,7 @@ function babelBuild(srcPath, envName) {
return babel.transformFileSync(srcPath, { envName }).code + '\n';
}

function buildJSFile(filepath) {
function buildFlowFile(filepath) {
const srcPath = path.join('./src', filepath);
const destPath = path.join('./dist', filepath);

Expand All @@ -108,6 +114,14 @@ function buildJSFile(filepath) {
writeFile(destPath.replace(/\.js$/, '.mjs'), babelBuild(srcPath, 'mjs'));
}

function buildTSEmittedJSFile(filepath) {
const srcPath = path.join('./ts-build', filepath);
const destPath = path.join('./dist', filepath);

writeFile(destPath, babelBuild(srcPath, 'cjs'));
writeFile(destPath.replace(/\.js$/, '.mjs'), babelBuild(srcPath, 'mjs'));
}

function buildPackageJSON() {
const packageJSON = require('../package.json');
delete packageJSON.private;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.