Skip to content

Commit

Permalink
[v4] drop support of Node.js 12/14/16, GraphQL 14/15 (#1793)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina committed Aug 1, 2023
1 parent 804f8b6 commit 6593482
Show file tree
Hide file tree
Showing 25 changed files with 342 additions and 2,043 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-planes-love.md
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': major
---

drop support of Node.js 12/14/16, GraphQL 14/15
7 changes: 0 additions & 7 deletions .eslintrc.cjs
Expand Up @@ -69,13 +69,6 @@ module.exports = {
node: true,
},
},
{
files: ['packages/plugin/src/**'],
rules: {
// remove in v4 major
'unicorn/prefer-node-protocol': 'off',
},
},
{
files: ['packages/plugin/src/rules/index.ts'],
rules: {
Expand Down
16 changes: 2 additions & 14 deletions .github/workflows/tests.yml
Expand Up @@ -35,12 +35,6 @@ jobs:
nodeVersion: 18
packageManager: pnpm

- name: Use GraphQL v${{matrix.graphql_version}}
run: node scripts/match-graphql.js ${{matrix.graphql_version}}

- name: Install Dependencies
run: pnpm i --no-frozen-lockfile

- name: Build
run: pnpm build

Expand All @@ -51,8 +45,8 @@ jobs:
needs: [typecheck]
strategy:
matrix:
node_version: [16, 18, 20]
graphql_version: [15, 16]
node_version: [18, 20]
graphql_version: [16]

steps:
- name: Checkout Master
Expand All @@ -66,12 +60,6 @@ jobs:
nodeVersion: ${{matrix.node_version}}
packageManager: pnpm

- name: Use GraphQL v${{matrix.graphql_version}}
run: node scripts/match-graphql.js ${{matrix.graphql_version}}

- name: Install Dependencies
run: pnpm i --no-frozen-lockfile

- name: Test
run: pnpm test
env:
Expand Down
3 changes: 0 additions & 3 deletions package.json
Expand Up @@ -50,9 +50,6 @@
"typescript": "5.1.6",
"vitest": "0.30.1"
},
"resolutions": {
"graphql": "16.7.1"
},
"pnpm": {
"patchedDependencies": {
"eslint@8.46.0": "patches/eslint@8.46.0.patch",
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/package.json
Expand Up @@ -6,7 +6,7 @@
"author": "Dotan Simha <dotansimha@gmail.com>",
"license": "MIT",
"engines": {
"node": ">=12"
"node": ">=18"
},
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -39,7 +39,7 @@
"test": "vitest"
},
"peerDependencies": {
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
"graphql": "^16"
},
"dependencies": {
"@graphql-tools/code-file-loader": "^7.3.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/documents.ts
@@ -1,4 +1,4 @@
import { resolve } from 'path';
import { resolve } from 'node:path';
import { Source } from '@graphql-tools/utils';
import debugFactory from 'debug';
import fg from 'fast-glob';
Expand Down
52 changes: 4 additions & 48 deletions packages/plugin/src/estree-converter/utils.ts
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import { AST } from 'eslint';
import { Comment, SourceLocation } from 'estree';
import {
Expand All @@ -25,40 +24,14 @@ export function getBaseType(type: GraphQLOutputType): GraphQLNamedType {
return type;
}

// Hardcoded type because tests fails on graphql 15
type TokenKindValue =
| ':'
| '!'
| '...'
| '('
| ')'
| '['
| ']'
| '{'
| '}'
| '@'
| '&'
// | '<EOF>'
| '<SOF>'
| '='
| '|'
| '$'
| 'BlockString'
| 'Comment'
| 'Float'
| 'Int'
| 'Name'
| 'String';

export function convertToken<T extends TokenKindValue | 'Block' | 'Line'>(
export function convertToken<T extends TokenKind | 'Block' | 'Line'>(
token: Token,
type: T,
): Omit<AST.Token, 'type'> & { type: T } {
const { line, column, end, start, value } = token;
return {
type,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- TODO: remove `!` when drop support of graphql@15
value: value!,
value,
/*
* ESLint has 0-based column number
* https://eslint.org/docs/developer-guide/working-with-rules#contextreport
Expand All @@ -77,25 +50,9 @@ export function convertToken<T extends TokenKindValue | 'Block' | 'Line'>(
};
}

function getLexer(source: Source): Lexer {
// GraphQL v14
const gqlLanguage = require('graphql/language');
if (gqlLanguage?.createLexer) {
return gqlLanguage.createLexer(source, {});
}

// GraphQL v15
const { Lexer: LexerCls } = require('graphql');
if (LexerCls && typeof LexerCls === 'function') {
return new LexerCls(source);
}

throw new Error('Unsupported GraphQL version! Please make sure to use GraphQL v14 or newer!');
}

export function extractTokens(filePath: string, code: string): AST.Token[] {
const source = new Source(code, filePath);
const lexer = getLexer(source);
const lexer = new Lexer(source);
const tokens: AST.Token[] = [];
let token = lexer.advance();

Expand All @@ -120,8 +77,7 @@ export function extractComments(loc?: Location): Comment[] {
const comment = convertToken(
token,
// `eslint-disable` directive works only with `Block` type comment
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- TODO: remove `!` when drop support of graphql@15
token.value!.trimStart().startsWith('eslint') ? 'Block' : 'Line',
token.value.trimStart().startsWith('eslint') ? 'Block' : 'Line',
);
comments.push(comment);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/graphql-config.ts
@@ -1,4 +1,4 @@
import { dirname } from 'path';
import { dirname } from 'node:path';
import { CodeFileLoader } from '@graphql-tools/code-file-loader';
import debugFactory from 'debug';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/processor.ts
@@ -1,4 +1,4 @@
import { relative } from 'path';
import { relative } from 'node:path';
import {
gqlPluckFromCodeStringSync,
GraphQLTagPluckOptions,
Expand Down

0 comments on commit 6593482

Please sign in to comment.